Skip to content

Commit 2faaa35

Browse files
committed
Rollup merge of rust-lang#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.
2 parents 26bc763 + cc46685 commit 2faaa35

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/libcore/str/lossy.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,15 @@ impl<'a> Iterator for Utf8LossyChunksIter<'a> {
6262
}
6363

6464
const TAG_CONT_U8: u8 = 128;
65-
fn unsafe_get(xs: &[u8], i: usize) -> u8 {
66-
unsafe { *xs.get_unchecked(i) }
67-
}
6865
fn safe_get(xs: &[u8], i: usize) -> u8 {
69-
if i >= xs.len() { 0 } else { unsafe_get(xs, i) }
66+
*xs.get(i).unwrap_or(&0)
7067
}
7168

7269
let mut i = 0;
7370
while i < self.source.len() {
7471
let i_ = i;
7572

76-
let byte = unsafe_get(self.source, i);
73+
let byte = unsafe { *self.source.get_unchecked(i) };
7774
i += 1;
7875

7976
if byte < 128 {

0 commit comments

Comments
 (0)