-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not implement unsafe auto traits for types with unsafe fields
If a type has unsafe fields, its safety invariants are not simply the conjunction of its field types' safety invariants. Consequently, it's invalid to reason about the safety properties of these types in a purely structural manner — i.e., the manner in which `auto` traits are implemented. Makes progress towards #132922.
- Loading branch information
Showing
16 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `UnsafeEnum: UnsafeAuto` is not satisfied | ||
--> $DIR/auto-traits.rs:24:22 | ||
| | ||
LL | impl_unsafe_auto(UnsafeEnum::Safe(42)); | ||
| ---------------- ^^^^^^^^^^^^^^^^^^^^ the trait `UnsafeAuto` is not implemented for `UnsafeEnum` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `impl_unsafe_auto` | ||
--> $DIR/auto-traits.rs:20:29 | ||
| | ||
LL | fn impl_unsafe_auto(_: impl UnsafeAuto) {} | ||
| ^^^^^^^^^^ required by this bound in `impl_unsafe_auto` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `UnsafeEnum: UnsafeAuto` is not satisfied | ||
--> $DIR/auto-traits.rs:24:22 | ||
| | ||
LL | impl_unsafe_auto(UnsafeEnum::Safe(42)); | ||
| ---------------- ^^^^^^^^^^^^^^^^^^^^ the trait `UnsafeAuto` is not implemented for `UnsafeEnum` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `impl_unsafe_auto` | ||
--> $DIR/auto-traits.rs:20:29 | ||
| | ||
LL | fn impl_unsafe_auto(_: impl UnsafeAuto) {} | ||
| ^^^^^^^^^^ required by this bound in `impl_unsafe_auto` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//@ compile-flags: --crate-type=lib | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
#![feature(auto_traits)] | ||
#![feature(unsafe_fields)] | ||
#![allow(incomplete_features)] | ||
|
||
enum UnsafeEnum { | ||
Safe(u8), | ||
Unsafe { unsafe field: u8 }, | ||
} | ||
|
||
auto trait SafeAuto {} | ||
|
||
fn impl_safe_auto(_: impl SafeAuto) {} | ||
|
||
unsafe auto trait UnsafeAuto {} | ||
|
||
fn impl_unsafe_auto(_: impl UnsafeAuto) {} | ||
|
||
fn tests() { | ||
impl_safe_auto(UnsafeEnum::Safe(42)); | ||
impl_unsafe_auto(UnsafeEnum::Safe(42)); | ||
//~^ ERROR the trait bound `UnsafeEnum: UnsafeAuto` is not satisfied | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.