diff options
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_unsafety.rs | 4 | ||||
| -rw-r--r-- | tests/ui/binding/issue-53114-safety-checks.rs | 1 | ||||
| -rw-r--r-- | tests/ui/binding/issue-53114-safety-checks.stderr | 30 | ||||
| -rw-r--r-- | tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr | 12 | ||||
| -rw-r--r-- | tests/ui/unsafe/unsafe-fn-deref-ptr.rs | 1 | ||||
| -rw-r--r-- | tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr | 2 |
6 files changed, 17 insertions, 33 deletions
diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index 2d7771ce61c..61f5586d736 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -100,7 +100,6 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { | StatementKind::StorageLive(..) | StatementKind::StorageDead(..) | StatementKind::Retag { .. } - | StatementKind::AscribeUserType(..) | StatementKind::PlaceMention(..) | StatementKind::Coverage(..) | StatementKind::Intrinsic(..) @@ -108,6 +107,9 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { | StatementKind::Nop => { // safe (at least as emitted during MIR construction) } + // `AscribeUserType` just exists to help MIR borrowck. It has no semantics, and + // everything is already reported by `PlaceMention`. + StatementKind::AscribeUserType(..) => return, } self.super_statement(statement, location); } diff --git a/tests/ui/binding/issue-53114-safety-checks.rs b/tests/ui/binding/issue-53114-safety-checks.rs index 0bffab32782..f4be2b482a7 100644 --- a/tests/ui/binding/issue-53114-safety-checks.rs +++ b/tests/ui/binding/issue-53114-safety-checks.rs @@ -36,7 +36,6 @@ fn let_ascribe_gets_unsafe_field() { let p = P { a: &2, b: &3 }; let _: _ = &p.b; //~ ERROR reference to packed field let _: _ = u1.a; //~ ERROR [E0133] - //~^ ERROR [E0133] let _: _ = &u2.a; //~ ERROR [E0133] // variation on above with `_` in substructure diff --git a/tests/ui/binding/issue-53114-safety-checks.stderr b/tests/ui/binding/issue-53114-safety-checks.stderr index 67902ac7b54..41318d0a38a 100644 --- a/tests/ui/binding/issue-53114-safety-checks.stderr +++ b/tests/ui/binding/issue-53114-safety-checks.stderr @@ -26,7 +26,7 @@ LL | let _: _ = &p.b; = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) error[E0793]: reference to packed field is unaligned - --> $DIR/issue-53114-safety-checks.rs:43:20 + --> $DIR/issue-53114-safety-checks.rs:42:20 | LL | let (_,): _ = (&p.b,); | ^^^^ @@ -35,7 +35,7 @@ LL | let (_,): _ = (&p.b,); = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) error[E0793]: reference to packed field is unaligned - --> $DIR/issue-53114-safety-checks.rs:52:11 + --> $DIR/issue-53114-safety-checks.rs:51:11 | LL | match &p.b { _ => { } } | ^^^^ @@ -44,7 +44,7 @@ LL | match &p.b { _ => { } } = help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers) error[E0793]: reference to packed field is unaligned - --> $DIR/issue-53114-safety-checks.rs:57:12 + --> $DIR/issue-53114-safety-checks.rs:56:12 | LL | match (&p.b,) { (_,) => { } } | ^^^^ @@ -93,15 +93,7 @@ LL | let _: _ = u1.a; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:38:12 - | -LL | let _: _ = u1.a; - | ^ access to union field - | - = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior - -error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:40:16 + --> $DIR/issue-53114-safety-checks.rs:39:16 | LL | let _: _ = &u2.a; | ^^^^^ access to union field @@ -109,7 +101,7 @@ LL | let _: _ = &u2.a; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:44:20 + --> $DIR/issue-53114-safety-checks.rs:43:20 | LL | let (_,): _ = (u1.a,); | ^^^^ access to union field @@ -117,7 +109,7 @@ LL | let (_,): _ = (u1.a,); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:45:20 + --> $DIR/issue-53114-safety-checks.rs:44:20 | LL | let (_,): _ = (&u2.a,); | ^^^^^ access to union field @@ -125,7 +117,7 @@ LL | let (_,): _ = (&u2.a,); = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:53:11 + --> $DIR/issue-53114-safety-checks.rs:52:11 | LL | match u1.a { _ => { } } | ^^^^ access to union field @@ -133,7 +125,7 @@ LL | match u1.a { _ => { } } = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:54:11 + --> $DIR/issue-53114-safety-checks.rs:53:11 | LL | match &u2.a { _ => { } } | ^^^^^ access to union field @@ -141,7 +133,7 @@ LL | match &u2.a { _ => { } } = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:58:12 + --> $DIR/issue-53114-safety-checks.rs:57:12 | LL | match (u1.a,) { (_,) => { } } | ^^^^ access to union field @@ -149,14 +141,14 @@ LL | match (u1.a,) { (_,) => { } } = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/issue-53114-safety-checks.rs:59:12 + --> $DIR/issue-53114-safety-checks.rs:58:12 | LL | match (&u2.a,) { (_,) => { } } | ^^^^^ access to union field | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior -error: aborting due to 19 previous errors +error: aborting due to 18 previous errors Some errors have detailed explanations: E0133, E0793. For more information about an error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr b/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr index ba89ad97275..24313352a41 100644 --- a/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr +++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.mir.stderr @@ -15,21 +15,13 @@ LL | let _: u8 = *p; = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-fn-deref-ptr.rs:6:12 - | -LL | let _: u8 = *p; - | ^^ dereference of raw pointer - | - = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-fn-deref-ptr.rs:8:12 + --> $DIR/unsafe-fn-deref-ptr.rs:7:12 | LL | return *p; | ^^ dereference of raw pointer | = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0133`. diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.rs b/tests/ui/unsafe/unsafe-fn-deref-ptr.rs index e5c16f044b0..ef8221d05cd 100644 --- a/tests/ui/unsafe/unsafe-fn-deref-ptr.rs +++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.rs @@ -4,7 +4,6 @@ fn f(p: *const u8) -> u8 { let _ = *p; //~ ERROR dereference of raw pointer is unsafe let _: u8 = *p; //~ ERROR dereference of raw pointer is unsafe - //[mir]~^ ERROR dereference of raw pointer is unsafe return *p; //~ ERROR dereference of raw pointer is unsafe } diff --git a/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr b/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr index f42a3f06037..24313352a41 100644 --- a/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr +++ b/tests/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr @@ -15,7 +15,7 @@ LL | let _: u8 = *p; = note: raw pointers may be null, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/unsafe-fn-deref-ptr.rs:8:12 + --> $DIR/unsafe-fn-deref-ptr.rs:7:12 | LL | return *p; | ^^ dereference of raw pointer |
