Skip to content

Commit 27d1cd8

Browse files
committed
Add safety annotations in iter::range
1 parent c25b82f commit 27d1cd8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libcore/iter/range.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ unsafe impl Step for char {
427427
res = Step::forward_checked(res, 0x800)?;
428428
}
429429
if res <= char::MAX as u32 {
430+
// SAFETY: res is a valid unicode scalar
431+
// (below 0x110000 and not in 0xD800..0xE000)
430432
Some(unsafe { char::from_u32_unchecked(res) })
431433
} else {
432434
None
@@ -440,6 +442,8 @@ unsafe impl Step for char {
440442
if start >= 0xE000 && 0xE000 > res {
441443
res = Step::backward_checked(res, 0x800)?;
442444
}
445+
// SAFETY: res is a valid unicode scalar
446+
// (below 0x110000 and not in 0xD800..0xE000)
443447
Some(unsafe { char::from_u32_unchecked(res) })
444448
}
445449

0 commit comments

Comments
 (0)