add an adt flag for MaybeDangling

This commit is contained in:
Waffle Lapkin
2025-10-29 19:25:57 +01:00
parent 8d50bccc5b
commit 7cefcb41ff
4 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -341,7 +341,8 @@ fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) {
PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);
ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::None;
ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::Exact(1);
MaybeDangling, sym::maybe_dangling, maybe_dangling, Target::Struct, GenericRequirement::Exact(1);
BikeshedGuaranteedNoDrop, sym::bikeshed_guaranteed_no_drop, bikeshed_guaranteed_no_drop, Target::Trait, GenericRequirement::Exact(0);
MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None;
+11
View File
@@ -62,6 +62,8 @@ impl AdtFlags: u16 {
const IS_PIN_PROJECT = 1 << 12;
/// Indicates whether the type is `FieldRepresentingType`.
const IS_FIELD_REPRESENTING_TYPE = 1 << 13;
/// Indicates whether the type is `MaybeDangling<_>`.
const IS_MAYBE_DANGLING = 1 << 14;
}
}
rustc_data_structures::external_bitflags_debug! { AdtFlags }
@@ -373,6 +375,9 @@ pub(super) fn new(
if tcx.is_lang_item(did, LangItem::ManuallyDrop) {
flags |= AdtFlags::IS_MANUALLY_DROP;
}
if tcx.is_lang_item(did, LangItem::MaybeDangling) {
flags |= AdtFlags::IS_MAYBE_DANGLING;
}
if tcx.is_lang_item(did, LangItem::UnsafeCell) {
flags |= AdtFlags::IS_UNSAFE_CELL;
}
@@ -500,6 +505,12 @@ pub fn is_manually_drop(self) -> bool {
self.flags().contains(AdtFlags::IS_MANUALLY_DROP)
}
/// Returns `true` if this is `MaybeDangling<T>`.
#[inline]
pub fn is_maybe_dangling(self) -> bool {
self.flags().contains(AdtFlags::IS_MAYBE_DANGLING)
}
/// Returns `true` if this is `Pin<T>`.
#[inline]
pub fn is_pin(self) -> bool {
+1
View File
@@ -1230,6 +1230,7 @@
maxnumf128,
may_dangle,
may_unwind,
maybe_dangling,
maybe_uninit,
maybe_uninit_uninit,
maybe_uninit_zeroed,
+1
View File
@@ -73,6 +73,7 @@
#[repr(transparent)]
#[rustc_pub_transparent]
#[derive(Debug, Copy, Clone, Default)]
#[lang = "maybe_dangling"]
pub struct MaybeDangling<P: ?Sized>(P);
impl<P: ?Sized> MaybeDangling<P> {