Skip to content

Commit 7a4b898

Browse files
authored
Rollup merge of rust-lang#136660 - compiler-errors:BikeshedGuaranteedNoDrop, r=lcnr
Use a trait to enforce field validity for union fields + `unsafe` fields + `unsafe<>` binder types This PR introduces a new, internal-only trait called `BikeshedGuaranteedNoDrop`[^1] to faithfully model the field check that used to be implemented manually by `allowed_union_or_unsafe_field`. https://github.com/rust-lang/rust/blob/942db6782f4a28c55b0b75b38fd4394d0483390f/compiler/rustc_hir_analysis/src/check/check.rs#L84-L115 Copying over the doc comment from the trait: ```rust /// Marker trait for the types that are allowed in union fields, unsafe fields, /// and unsafe binder types. /// /// Implemented for: /// * `&T`, `&mut T` for all `T`, /// * `ManuallyDrop<T>` for all `T`, /// * tuples and arrays whose elements implement `BikeshedGuaranteedNoDrop`, /// * or otherwise, all types that are `Copy`. /// /// Notably, this doesn't include all trivially-destructible types for semver /// reasons. /// /// Bikeshed name for now. ``` As far as I am aware, there's no new behavior being guaranteed by this trait, since it operates the same as the manually implemented check. We could easily rip out this trait and go back to using the manually implemented check for union fields, however using a trait means that this code can be shared by WF for `unsafe<>` binders too. See the last commit. The only diagnostic changes are that this now fires false-negatives for fields that are ill-formed. I don't consider that to be much of a problem though. r? oli-obk [^1]: Please let's not bikeshed this name lol. There's no good name for `ValidForUnsafeFieldsUnsafeBindersAndUnionFields`.
2 parents f9116db + c6ddd33 commit 7a4b898

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

example/mini_core.rs

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ impl<T: ?Sized> LegacyReceiver for Box<T> {}
5757
#[lang = "copy"]
5858
pub trait Copy {}
5959

60+
#[lang = "bikeshed_guaranteed_no_drop"]
61+
pub trait BikeshedGuaranteedNoDrop {}
62+
6063
impl Copy for bool {}
6164
impl Copy for u8 {}
6265
impl Copy for u16 {}

0 commit comments

Comments
 (0)