Skip to content

Commit c14a771

Browse files
committed
No longer walk (inline) constants with UnusedUnsafeVisitor
1 parent f3a5992 commit c14a771

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_mir_transform/src/check_unsafety.rs

+2
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_, 'tcx> {
439439
}
440440
intravisit::walk_block(self, block);
441441
}
442+
443+
fn visit_anon_const(&mut self, _c: &'tcx hir::AnonConst) {}
442444
}
443445

444446
fn check_unused_unsafe(

src/test/ui/span/lint-unused-unsafe.mir.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -1140,5 +1140,17 @@ LL | async unsafe fn async_blocks() {
11401140
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
11411141
| ^^^^^^ unnecessary `unsafe` block
11421142

1143-
error: aborting due to 140 previous errors
1143+
error: unnecessary `unsafe` block
1144+
--> $DIR/lint-unused-unsafe.rs:754:22
1145+
|
1146+
LL | let _x: [(); unsafe { 0 }] = [];
1147+
| ^^^^^^ unnecessary `unsafe` block
1148+
1149+
error: unnecessary `unsafe` block
1150+
--> $DIR/lint-unused-unsafe.rs:758:22
1151+
|
1152+
LL | let _x: [(); unsafe { unsafe { size() } }] = [];
1153+
| ^^^^^^ unnecessary `unsafe` block
1154+
1155+
error: aborting due to 142 previous errors
11441156

src/test/ui/span/lint-unused-unsafe.rs

+14
Original file line numberDiff line numberDiff line change
@@ -745,4 +745,18 @@ mod additional_tests_extra {
745745
}};
746746
}
747747
}
748+
749+
fn used_unsafe_in_const() {
750+
let _x: [(); unsafe { size() }] = [];
751+
}
752+
753+
fn unused_unsafe_in_const_1() {
754+
let _x: [(); unsafe { 0 }] = []; //~ ERROR: unnecessary `unsafe` block
755+
}
756+
757+
fn unused_unsafe_in_const_2() {
758+
let _x: [(); unsafe { unsafe { size() } }] = []; //~ ERROR: unnecessary `unsafe` block
759+
}
760+
761+
const unsafe fn size() -> usize { 0 }
748762
}

0 commit comments

Comments
 (0)