mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
make field representing types invariant over the base type
Reported-by: David Rheinsberg <david@readahead.eu> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/Multiple.20LockedBy.20with.20Single.20Lock/near/579275908
This commit is contained in:
@@ -8,7 +8,10 @@
|
||||
#[expect(missing_debug_implementations)]
|
||||
#[fundamental]
|
||||
pub struct FieldRepresentingType<T: ?Sized, const VARIANT: u32, const FIELD: u32> {
|
||||
_phantom: PhantomData<T>,
|
||||
// We want this type to be invariant over `T`, because otherwise `field_of!(Struct<'short>,
|
||||
// field)` is a subtype of `field_of!(Struct<'long>, field)`. This subtype relationship does not
|
||||
// have an immediately obvious meaning and we want to prevent people from relying on it.
|
||||
_phantom: PhantomData<fn(T) -> T>,
|
||||
}
|
||||
|
||||
// SAFETY: `FieldRepresentingType` doesn't contain any `T`
|
||||
|
||||
Reference in New Issue
Block a user