about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-11-29 13:10:41 +0100
committerGitHub <noreply@github.com>2018-11-29 13:10:41 +0100
commit1b7da84e9d2c29d03d34f9b6804af67f51e41a6b (patch)
tree39dd82908dd2b086a8a3b8ee8e39359c88106466
parent5bc98a731dcc0e37afdd68c70de83e870d26349f (diff)
parentcc466851bc458219121142ae75f5cc47bb3a927f (diff)
downloadrust-1b7da84e9d2c29d03d34f9b6804af67f51e41a6b.tar.gz
rust-1b7da84e9d2c29d03d34f9b6804af67f51e41a6b.zip
Rollup merge of #56236 - frewsxcv:frewsxcv-unsafe-unsafe, r=cramertj
Remove unsafe `unsafe` inner function.

Within this `Iterator` implementation, a function `unsafe_get` is
defined which unsafely allows _unchecked_ indexing of any element in a
slice. This should be marked as _unsafe_, but it is not.

To address this issue, I removed that inner function.
-rw-r--r--src/libcore/str/lossy.rs7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/libcore/str/lossy.rs b/src/libcore/str/lossy.rs
index 186d6adbc91..52abd8f9952 100644
--- a/src/libcore/str/lossy.rs
+++ b/src/libcore/str/lossy.rs
@@ -62,18 +62,15 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> {
         }
 
         const TAG_CONT_U8: u8 = 128;
-        fn unsafe_get(xs: &[u8], i: usize) -> u8 {
-            unsafe { *xs.get_unchecked(i) }
-        }
         fn safe_get(xs: &[u8], i: usize) -> u8 {
-            if i >= xs.len() { 0 } else { unsafe_get(xs, i) }
+            *xs.get(i).unwrap_or(&0)
         }
 
         let mut i = 0;
         while i < self.source.len() {
             let i_ = i;
 
-            let byte = unsafe_get(self.source, i);
+            let byte = unsafe { *self.source.get_unchecked(i) };
             i += 1;
 
             if byte < 128 {