Skip to content

Commit cd6a8ca

Browse files
committed
FIx off-by-one in char::steps_between
1 parent b1d1f25 commit cd6a8ca

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/libcore/iter/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ unsafe impl Step for char {
408408
let start = start as u32;
409409
let end = end as u32;
410410
if start <= end {
411-
let count = end - start + 1;
411+
let count = end - start;
412412
if start < 0xD800 && 0xE000 <= end {
413413
usize::try_from(count - 0x800).ok()
414414
} else {

src/libcore/tests/iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,9 @@ fn test_char_range() {
19391939
assert!(('\0'..=char::MAX).rev().eq((0..=char::MAX as u32).filter_map(char::from_u32).rev()));
19401940

19411941
assert_eq!(('\u{D7FF}'..='\u{E000}').count(), 2);
1942+
assert_eq!(('\u{D7FF}'..='\u{E000}').size_hint(), (2, Some(2)));
19421943
assert_eq!(('\u{D7FF}'..'\u{E000}').count(), 1);
1944+
assert_eq!(('\u{D7FF}'..'\u{E000}').size_hint(), (1, Some(1)));
19431945
}
19441946

19451947
#[test]

0 commit comments

Comments
 (0)