1
Fork 0

Ignore AscribeUserType in unsafeck to avoid duplicate diagnostics.

This commit is contained in:
Camille GILLOT 2022-11-26 13:16:47 +00:00
parent 4462bb54e3
commit e107194b66
6 changed files with 17 additions and 33 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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`.

View file

@ -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`.

View file

@ -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
}

View file

@ -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