-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not implement unsafe auto traits for types with unsafe fields #133934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please adjust this logic in the new trait solver too. Also, there's no test as far as I can tell.
Also make sure the test exercises the behavior in both the old and new solvers. You can do something like:
|
e6e322f
to
baec50e
Compare
Whoops, somehow failed to push the test I wrote. It's here: https://github.com/rust-lang/rust/compare/e6e322f79713b156d43d77be6135463ec2d4b6e7..baec50ee0b8afc7433c3bd2f2b862a21addd2f57 |
|
||
#![feature(auto_traits)] | ||
#![feature(unsafe_fields)] | ||
#![allow(dead_code, incomplete_features, unconditional_recursion)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the unconditional_recursion
. No reason not to just split this out into a fn main() {}
or something that just calls both of the functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for dead_code
, that's enabled in the UI test suite unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baec50e
to
9d604ce
Compare
This comment has been minimized.
This comment has been minimized.
|
9d604ce
to
9ccf285
Compare
@@ -136,6 +136,9 @@ pub trait Ty<I: Interner<Ty = Self>>: | |||
matches!(self.kind(), ty::FnPtr(..)) | |||
} | |||
|
|||
/// Checks whether this type directly contains unsafe fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Checks whether this type directly contains unsafe fields. | |
/// Checks whether this type is an ADT that has unsafe fields. |
@bors r+ |
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 rust-lang#132922.
9ccf285
to
a122dde
Compare
@bors r+ |
@bors r=compiler-errors |
💡 This pull request was already approved, no need to approve it again.
|
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#130209 (Stabilize `std::io::ErrorKind::CrossesDevices`) - rust-lang#130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`) - rust-lang#132187 (Add Extend impls for tuples of arity 1 through 12) - rust-lang#133875 (handle `--json-output` properly) - rust-lang#133934 (Do not implement unsafe auto traits for types with unsafe fields) - rust-lang#133954 (Hide errors whose suggestions would contain error constants or types) - rust-lang#133960 (rustdoc: remove eq for clean::Attributes) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#130209 (Stabilize `std::io::ErrorKind::CrossesDevices`) - rust-lang#130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`) - rust-lang#132187 (Add Extend impls for tuples of arity 1 through 12) - rust-lang#133875 (handle `--json-output` properly) - rust-lang#133934 (Do not implement unsafe auto traits for types with unsafe fields) - rust-lang#133954 (Hide errors whose suggestions would contain error constants or types) - rust-lang#133960 (rustdoc: remove eq for clean::Attributes) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#130209 (Stabilize `std::io::ErrorKind::CrossesDevices`) - rust-lang#130254 (Stabilize `std::io::ErrorKind::QuotaExceeded`) - rust-lang#132187 (Add Extend impls for tuples of arity 1 through 12) - rust-lang#133875 (handle `--json-output` properly) - rust-lang#133934 (Do not implement unsafe auto traits for types with unsafe fields) - rust-lang#133954 (Hide errors whose suggestions would contain error constants or types) - rust-lang#133960 (rustdoc: remove eq for clean::Attributes) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133934 - jswrenn:unsafe-fields-auto-traits, r=compiler-errors 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. Consequently, auto implementations of unsafe auto traits should not be generated for types with unsafe fields. Tracking: rust-lang#132922 r? `@compiler-errors`
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. Consequently, auto implementations of unsafe auto traits should not be generated for types with unsafe fields.Tracking: #132922
r? @compiler-errors