Skip to content

Commit

Permalink
Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
Browse files Browse the repository at this point in the history
Fix ICE in `undocumented_unsafe_blocks`

fixes #8681

changelog: Fix ICE in `undocumented_unsafe_blocks`
  • Loading branch information
bors committed Apr 12, 2022
2 parents bc069ef + c82dd0f commit b3bd03a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clippy_lints/src/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
.array_windows::<2>()
.rev()
.map_while(|[start, end]| {
src.get(start.to_usize() - offset..end.to_usize() - offset)
.map(|text| (start.to_usize(), text.trim_start()))
let start = start.to_usize() - offset;
let end = end.to_usize() - offset;
src.get(start..end).map(|text| (start, text.trim_start()))
})
.filter(|(_, text)| !text.is_empty());

Expand All @@ -182,7 +183,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
let (mut line_start, mut line) = (line_start, line);
loop {
if line.starts_with("/*") {
let src = src[line_start..line_starts.last().unwrap().to_usize()].trim_start();
let src = src[line_start..line_starts.last().unwrap().to_usize() - offset].trim_start();
let mut tokens = tokenize(src);
return src[..tokens.next().unwrap().len]
.to_ascii_uppercase()
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/crashes/auxiliary/ice-8681-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub fn foo(x: &u32) -> u32 {
/* Safety:
* This is totally ok.
*/
unsafe { *(x as *const u32) }
}
10 changes: 10 additions & 0 deletions tests/ui/crashes/ice-8681.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// aux-build: ice-8681-aux.rs

#![warn(clippy::undocumented_unsafe_blocks)]

#[path = "auxiliary/ice-8681-aux.rs"]
mod ice_8681_aux;

fn main() {
let _ = ice_8681_aux::foo(&0u32);
}

0 comments on commit b3bd03a

Please sign in to comment.