diff options
| author | bors <bors@rust-lang.org> | 2021-11-08 10:48:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-08 10:48:34 +0000 |
| commit | 6fcdf819391585804014e1cabfc2dd03073c9169 (patch) | |
| tree | f37cd0da01c839209e487fa39c4998d364a80051 | |
| parent | 07f4f7c2dd07fce07b0d6d3c95eb01ed80b47638 (diff) | |
| parent | 2c6f03d48bd25294187eca27c5357620f612c656 (diff) | |
| download | rust-6fcdf819391585804014e1cabfc2dd03073c9169.tar.gz rust-6fcdf819391585804014e1cabfc2dd03073c9169.zip | |
Auto merge of #7945 - Serial-ATA:issue-7934, r=flip1995
Fix ICE in undocumented_unsafe_blocks changelog: Fix ICE in [`undocumented_unsafe_blocks`] closes: #7934
| -rw-r--r-- | clippy_lints/src/undocumented_unsafe_blocks.rs | 4 | ||||
| -rw-r--r-- | tests/ui/crashes/auxiliary/ice-7934-aux.rs | 4 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-7934.rs | 7 |
3 files changed, 14 insertions, 1 deletions
diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 99b33e5433f..fbf66712261 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -149,6 +149,8 @@ impl UndocumentedUnsafeBlocks { let lex_end = (between_span.hi().0 - source_file.start_pos.0) as usize; let src_str = source_file.src.as_ref()?[lex_start..lex_end].to_string(); + let source_start_pos = source_file.start_pos.0 as usize + lex_start; + let mut pos = 0; let mut comment = false; @@ -171,7 +173,7 @@ impl UndocumentedUnsafeBlocks { if comment { // Get the line number of the "comment" (really wherever the trailing whitespace ended) let comment_line_num = source_file - .lookup_file_pos_with_col_display(BytePos((lex_start + pos).try_into().unwrap())) + .lookup_file_pos(BytePos((source_start_pos + pos).try_into().unwrap())) .0; // Find the block/local's line number let block_line_num = tcx.sess.source_map().lookup_char_pos(block_span.lo()).line; diff --git a/tests/ui/crashes/auxiliary/ice-7934-aux.rs b/tests/ui/crashes/auxiliary/ice-7934-aux.rs new file mode 100644 index 00000000000..4afbf027b61 --- /dev/null +++ b/tests/ui/crashes/auxiliary/ice-7934-aux.rs @@ -0,0 +1,4 @@ +fn zero() { + // SAFETY: + unsafe { 0 }; +} diff --git a/tests/ui/crashes/ice-7934.rs b/tests/ui/crashes/ice-7934.rs new file mode 100644 index 00000000000..a4691c4131b --- /dev/null +++ b/tests/ui/crashes/ice-7934.rs @@ -0,0 +1,7 @@ +#![warn(clippy::undocumented_unsafe_blocks)] +#![allow(clippy::no_effect)] + +#[path = "auxiliary/ice-7934-aux.rs"] +mod zero; + +fn main() {} |
