Skip to content

Commit

Permalink
Auto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks…
Browse files Browse the repository at this point in the history
…, r=flip1995

Fix ICE on `undocumented_unsafe_blocks`

fix #7979

changelog: Fix ICE on `undocumented_unsafe_blocks`
  • Loading branch information
bors committed Nov 17, 2021
2 parents 94ca94f + 3f3d7c2 commit d550e5f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ impl UndocumentedUnsafeBlocks {

let between_span = if block_span.from_expansion() {
self.macro_expansion = true;
enclosing_scope_span.with_hi(block_span.hi())
enclosing_scope_span.with_hi(block_span.hi()).source_callsite()
} else {
self.macro_expansion = false;
enclosing_scope_span.to(block_span)
enclosing_scope_span.to(block_span).source_callsite()
};

let file_name = source_map.span_to_filename(between_span);
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/undocumented_unsafe_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,8 @@ fn interference() {
unsafe {};
}

pub fn print_binary_tree() {
println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
}

fn main() {}
14 changes: 13 additions & 1 deletion tests/ui/undocumented_unsafe_blocks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,17 @@ LL ~ // Safety: ...
LL ~ unsafe {};
|

error: aborting due to 13 previous errors
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:288:20
|
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider adding a safety comment
|
LL ~ println!("{}", // Safety: ...
LL ~ unsafe { String::from_utf8_unchecked(vec![]) });
|

error: aborting due to 14 previous errors

0 comments on commit d550e5f

Please sign in to comment.