Skip to content

Commit

Permalink
No longer walk (inline) constants with UnusedUnsafeVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
steffahn committed Feb 5, 2022
1 parent f3a5992 commit c14a771
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/rustc_mir_transform/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_, 'tcx> {
}
intravisit::walk_block(self, block);
}

fn visit_anon_const(&mut self, _c: &'tcx hir::AnonConst) {}
}

fn check_unused_unsafe(
Expand Down
14 changes: 13 additions & 1 deletion src/test/ui/span/lint-unused-unsafe.mir.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -1140,5 +1140,17 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block

error: aborting due to 140 previous errors
error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:754:22
|
LL | let _x: [(); unsafe { 0 }] = [];
| ^^^^^^ unnecessary `unsafe` block

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:758:22
|
LL | let _x: [(); unsafe { unsafe { size() } }] = [];
| ^^^^^^ unnecessary `unsafe` block

error: aborting due to 142 previous errors

14 changes: 14 additions & 0 deletions src/test/ui/span/lint-unused-unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,18 @@ mod additional_tests_extra {
}};
}
}

fn used_unsafe_in_const() {
let _x: [(); unsafe { size() }] = [];
}

fn unused_unsafe_in_const_1() {
let _x: [(); unsafe { 0 }] = []; //~ ERROR: unnecessary `unsafe` block
}

fn unused_unsafe_in_const_2() {
let _x: [(); unsafe { unsafe { size() } }] = []; //~ ERROR: unnecessary `unsafe` block
}

const unsafe fn size() -> usize { 0 }
}

0 comments on commit c14a771

Please sign in to comment.