Skip to content

Commit 7788af9

Browse files
committed
Auto merge of rust-lang#7891 - giraffate:fix_ice_for_undocumented_unsafe_blocks, r=flip1995
Fix ice in `undocumented_unsafe_blocks` Fix rust-lang/rust-clippy#7868 changelog: Fix ice in [`undocumented_unsafe_blocks`]
2 parents 89a1156 + 35bf041 commit 7788af9

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ impl UndocumentedUnsafeBlocks {
145145
let file_name = source_map.span_to_filename(between_span);
146146
let source_file = source_map.get_source_file(&file_name)?;
147147

148-
let lex_start = (between_span.lo().0 + 1) as usize;
149-
let src_str = source_file.src.as_ref()?[lex_start..between_span.hi().0 as usize].to_string();
148+
let lex_start = (between_span.lo().0 - source_file.start_pos.0 + 1) as usize;
149+
let lex_end = (between_span.hi().0 - source_file.start_pos.0) as usize;
150+
let src_str = source_file.src.as_ref()?[lex_start..lex_end].to_string();
150151

151152
let mut pos = 0;
152153
let mut comment = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn zero() {
2+
unsafe { 0 };
3+
}

tests/ui/crashes/ice-7868.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![warn(clippy::undocumented_unsafe_blocks)]
2+
#![allow(clippy::no_effect)]
3+
4+
#[path = "auxiliary/ice-7868-aux.rs"]
5+
mod zero;
6+
7+
fn main() {}

tests/ui/crashes/ice-7868.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unsafe block missing a safety comment
2+
--> $DIR/auxiliary/ice-7868-aux.rs:2:5
3+
|
4+
LL | unsafe { 0 };
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
8+
help: consider adding a safety comment
9+
|
10+
LL ~ // Safety: ...
11+
LL ~ unsafe { 0 };
12+
|
13+
14+
error: aborting due to previous error
15+

0 commit comments

Comments
 (0)