From 7cefcb41ff7e27f3619bfecff429f72b5f3bface Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Wed, 29 Oct 2025 19:25:57 +0100 Subject: [PATCH] add an adt flag for `MaybeDangling` --- compiler/rustc_hir/src/lang_items.rs | 3 ++- compiler/rustc_middle/src/ty/adt.rs | 11 +++++++++++ compiler/rustc_span/src/symbol.rs | 1 + library/core/src/mem/maybe_dangling.rs | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 9ec681c37457..80f0af9d663c 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -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; diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index c141eb0311dc..8feca4a9bd02 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -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`. + #[inline] + pub fn is_maybe_dangling(self) -> bool { + self.flags().contains(AdtFlags::IS_MAYBE_DANGLING) + } + /// Returns `true` if this is `Pin`. #[inline] pub fn is_pin(self) -> bool { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 9a2d68fc6639..6d36ba999a2f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1230,6 +1230,7 @@ maxnumf128, may_dangle, may_unwind, + maybe_dangling, maybe_uninit, maybe_uninit_uninit, maybe_uninit_zeroed, diff --git a/library/core/src/mem/maybe_dangling.rs b/library/core/src/mem/maybe_dangling.rs index a5f77e667f97..914ae33414ef 100644 --- a/library/core/src/mem/maybe_dangling.rs +++ b/library/core/src/mem/maybe_dangling.rs @@ -73,6 +73,7 @@ #[repr(transparent)] #[rustc_pub_transparent] #[derive(Debug, Copy, Clone, Default)] +#[lang = "maybe_dangling"] pub struct MaybeDangling(P); impl MaybeDangling

{