Skip to content

Commit b3bd03a

Browse files
committed
Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
Fix ICE in `undocumented_unsafe_blocks` fixes #8681 changelog: Fix ICE in `undocumented_unsafe_blocks`
2 parents bc069ef + c82dd0f commit b3bd03a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
156156
.array_windows::<2>()
157157
.rev()
158158
.map_while(|[start, end]| {
159-
src.get(start.to_usize() - offset..end.to_usize() - offset)
160-
.map(|text| (start.to_usize(), text.trim_start()))
159+
let start = start.to_usize() - offset;
160+
let end = end.to_usize() - offset;
161+
src.get(start..end).map(|text| (start, text.trim_start()))
161162
})
162163
.filter(|(_, text)| !text.is_empty());
163164

@@ -182,7 +183,7 @@ fn text_has_safety_comment(src: &str, line_starts: &[BytePos], offset: usize) ->
182183
let (mut line_start, mut line) = (line_start, line);
183184
loop {
184185
if line.starts_with("/*") {
185-
let src = src[line_start..line_starts.last().unwrap().to_usize()].trim_start();
186+
let src = src[line_start..line_starts.last().unwrap().to_usize() - offset].trim_start();
186187
let mut tokens = tokenize(src);
187188
return src[..tokens.next().unwrap().len]
188189
.to_ascii_uppercase()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub fn foo(x: &u32) -> u32 {
2+
/* Safety:
3+
* This is totally ok.
4+
*/
5+
unsafe { *(x as *const u32) }
6+
}

tests/ui/crashes/ice-8681.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build: ice-8681-aux.rs
2+
3+
#![warn(clippy::undocumented_unsafe_blocks)]
4+
5+
#[path = "auxiliary/ice-8681-aux.rs"]
6+
mod ice_8681_aux;
7+
8+
fn main() {
9+
let _ = ice_8681_aux::foo(&0u32);
10+
}

0 commit comments

Comments
 (0)