Skip to content

Commit 2c6f03d

Browse files
committed
Fix ICE in undocumented_unsafe_blocks
1 parent 07f4f7c commit 2c6f03d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ impl UndocumentedUnsafeBlocks {
149149
let lex_end = (between_span.hi().0 - source_file.start_pos.0) as usize;
150150
let src_str = source_file.src.as_ref()?[lex_start..lex_end].to_string();
151151

152+
let source_start_pos = source_file.start_pos.0 as usize + lex_start;
153+
152154
let mut pos = 0;
153155
let mut comment = false;
154156

@@ -171,7 +173,7 @@ impl UndocumentedUnsafeBlocks {
171173
if comment {
172174
// Get the line number of the "comment" (really wherever the trailing whitespace ended)
173175
let comment_line_num = source_file
174-
.lookup_file_pos_with_col_display(BytePos((lex_start + pos).try_into().unwrap()))
176+
.lookup_file_pos(BytePos((source_start_pos + pos).try_into().unwrap()))
175177
.0;
176178
// Find the block/local's line number
177179
let block_line_num = tcx.sess.source_map().lookup_char_pos(block_span.lo()).line;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn zero() {
2+
// SAFETY:
3+
unsafe { 0 };
4+
}

tests/ui/crashes/ice-7934.rs

Lines changed: 7 additions & 0 deletions
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-7934-aux.rs"]
5+
mod zero;
6+
7+
fn main() {}

0 commit comments

Comments
 (0)