Skip to content

Commit

Permalink
FIx off-by-one in char::steps_between
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed May 28, 2020
1 parent b1d1f25 commit cd6a8ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ unsafe impl Step for char {
let start = start as u32;
let end = end as u32;
if start <= end {
let count = end - start + 1;
let count = end - start;
if start < 0xD800 && 0xE000 <= end {
usize::try_from(count - 0x800).ok()
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,9 @@ fn test_char_range() {
assert!(('\0'..=char::MAX).rev().eq((0..=char::MAX as u32).filter_map(char::from_u32).rev()));

assert_eq!(('\u{D7FF}'..='\u{E000}').count(), 2);
assert_eq!(('\u{D7FF}'..='\u{E000}').size_hint(), (2, Some(2)));
assert_eq!(('\u{D7FF}'..'\u{E000}').count(), 1);
assert_eq!(('\u{D7FF}'..'\u{E000}').size_hint(), (1, Some(1)));
}

#[test]
Expand Down

0 comments on commit cd6a8ca

Please sign in to comment.