Skip to content

Commit

Permalink
Add safety annotations in iter::range
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed May 21, 2020
1 parent c25b82f commit 27d1cd8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ unsafe impl Step for char {
res = Step::forward_checked(res, 0x800)?;
}
if res <= char::MAX as u32 {
// SAFETY: res is a valid unicode scalar
// (below 0x110000 and not in 0xD800..0xE000)
Some(unsafe { char::from_u32_unchecked(res) })
} else {
None
Expand All @@ -440,6 +442,8 @@ unsafe impl Step for char {
if start >= 0xE000 && 0xE000 > res {
res = Step::backward_checked(res, 0x800)?;
}
// SAFETY: res is a valid unicode scalar
// (below 0x110000 and not in 0xD800..0xE000)
Some(unsafe { char::from_u32_unchecked(res) })
}

Expand Down

0 comments on commit 27d1cd8

Please sign in to comment.