Skip to content

Commit

Permalink
Rollup merge of rust-lang#56236 - frewsxcv:frewsxcv-unsafe-unsafe, r=…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
pietroalbini committed Nov 28, 2018
2 parents 26bc763 + cc46685 commit 2faaa35
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/libcore/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2faaa35

Please sign in to comment.