Skip to content

Commit

Permalink
Auto merge of rust-lang#7891 - giraffate:fix_ice_for_undocumented_uns…
Browse files Browse the repository at this point in the history
…afe_blocks, r=flip1995

Fix ice in `undocumented_unsafe_blocks`

Fix rust-lang/rust-clippy#7868

changelog: Fix ice in [`undocumented_unsafe_blocks`]
  • Loading branch information
bors committed Oct 28, 2021
2 parents 89a1156 + 35bf041 commit 7788af9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clippy_lints/src/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ impl UndocumentedUnsafeBlocks {
let file_name = source_map.span_to_filename(between_span);
let source_file = source_map.get_source_file(&file_name)?;

let lex_start = (between_span.lo().0 + 1) as usize;
let src_str = source_file.src.as_ref()?[lex_start..between_span.hi().0 as usize].to_string();
let lex_start = (between_span.lo().0 - source_file.start_pos.0 + 1) as usize;
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 mut pos = 0;
let mut comment = false;
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/crashes/auxiliary/ice-7868-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn zero() {
unsafe { 0 };
}
7 changes: 7 additions & 0 deletions tests/ui/crashes/ice-7868.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::undocumented_unsafe_blocks)]
#![allow(clippy::no_effect)]

#[path = "auxiliary/ice-7868-aux.rs"]
mod zero;

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/crashes/ice-7868.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: unsafe block missing a safety comment
--> $DIR/auxiliary/ice-7868-aux.rs:2:5
|
LL | unsafe { 0 };
| ^^^^^^^^^^^^
|
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
help: consider adding a safety comment
|
LL ~ // Safety: ...
LL ~ unsafe { 0 };
|

error: aborting due to previous error

0 comments on commit 7788af9

Please sign in to comment.