diff options
Diffstat (limited to 'src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs')
-rw-r--r-- | src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs new file mode 100644 index 000000000..3e3da667c --- /dev/null +++ b/src/test/ui/unsafe/issue-45087-unreachable-unsafe.rs @@ -0,0 +1,31 @@ +// Verify that unreachable code undergoes unsafety checks. +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + +fn main() { + return; + *(1 as *mut u32) = 42; + //~^ ERROR dereference of raw pointer is unsafe +} + +fn panic() -> ! { + panic!(); +} + +fn f(a: *mut u32) { + panic(); + *a = 1; + //~^ ERROR dereference of raw pointer is unsafe +} + +enum Void {} + +fn uninhabited() -> Void { + panic!(); +} + +fn g(b: *mut u32) { + uninhabited(); + *b = 1; + //~^ ERROR dereference of raw pointer is unsafe +} |