Skip to content

Commit d550e5f

Browse files
committed
Auto merge of rust-lang#7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995
Fix ICE on `undocumented_unsafe_blocks` fix rust-lang/rust-clippy#7979 changelog: Fix ICE on `undocumented_unsafe_blocks`
2 parents 94ca94f + 3f3d7c2 commit d550e5f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ impl UndocumentedUnsafeBlocks {
137137

138138
let between_span = if block_span.from_expansion() {
139139
self.macro_expansion = true;
140-
enclosing_scope_span.with_hi(block_span.hi())
140+
enclosing_scope_span.with_hi(block_span.hi()).source_callsite()
141141
} else {
142142
self.macro_expansion = false;
143-
enclosing_scope_span.to(block_span)
143+
enclosing_scope_span.to(block_span).source_callsite()
144144
};
145145

146146
let file_name = source_map.span_to_filename(between_span);

tests/ui/undocumented_unsafe_blocks.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,8 @@ fn interference() {
284284
unsafe {};
285285
}
286286

287+
pub fn print_binary_tree() {
288+
println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
289+
}
290+
287291
fn main() {}

tests/ui/undocumented_unsafe_blocks.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,17 @@ LL ~ // Safety: ...
155155
LL ~ unsafe {};
156156
|
157157

158-
error: aborting due to 13 previous errors
158+
error: unsafe block missing a safety comment
159+
--> $DIR/undocumented_unsafe_blocks.rs:288:20
160+
|
161+
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
162+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
163+
|
164+
help: consider adding a safety comment
165+
|
166+
LL ~ println!("{}", // Safety: ...
167+
LL ~ unsafe { String::from_utf8_unchecked(vec![]) });
168+
|
169+
170+
error: aborting due to 14 previous errors
159171

0 commit comments

Comments
 (0)