diff --git a/library/core/src/char/decode.rs b/library/core/src/char/decode.rs index 4784418f98c50..a0d6890ec908f 100644 --- a/library/core/src/char/decode.rs +++ b/library/core/src/char/decode.rs @@ -122,7 +122,12 @@ impl> Iterator for DecodeUtf16 { let (low, high) = self.iter.size_hint(); // we could be entirely valid surrogates (2 elements per // char), or entirely non-surrogates (1 element per char) - (low / 2, high) + // + // In addition to `self.iter`, there's potentially one + // additional number in `self.buf`. + // On odd lower bound, at least one element must stay unpaired + // (with other elements from `self.iter`). + (low.div_ceil(2), try { high?.checked_add(1)? }) } }