about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCAD97 <cad97@cad97.com>2020-05-21 13:21:55 -0400
committerCAD97 <cad97@cad97.com>2020-05-21 13:44:54 -0400
commit27d1cd857e8998c423f329efce7c995a26dcdb6c (patch)
treec1e019966d58084bd3a77c7eeb11d6c3d946dbb1
parentc25b82f5bb9770374db31906dedb497034a151fd (diff)
downloadrust-27d1cd857e8998c423f329efce7c995a26dcdb6c.tar.gz
rust-27d1cd857e8998c423f329efce7c995a26dcdb6c.zip
Add safety annotations in iter::range
-rw-r--r--src/libcore/iter/range.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs
index 3fa4cf2ca0d..5db790e491c 100644
--- a/src/libcore/iter/range.rs
+++ b/src/libcore/iter/range.rs
@@ -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
@@ -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) })
     }