Skip to content

Commit fa5e283

Browse files
committed
Add comments, and fix issue 88762
1 parent bea5cd1 commit fa5e283

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/core/src/char/decode.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
122122
let (low, high) = self.iter.size_hint();
123123
// we could be entirely valid surrogates (2 elements per
124124
// char), or entirely non-surrogates (1 element per char)
125-
(low.div_ceil(2), high)
125+
//
126+
// In addition to `self.iter`, there's potentially one
127+
// additional number in `self.buf`.
128+
// On odd lower bound, at least one element must stay unpaired
129+
// (with other elements from `self.iter`).
130+
(low.div_ceil(2), try { high?.checked_add(1)? })
126131
}
127132
}
128133

0 commit comments

Comments
 (0)