Skip to content

Commit 68a92e9

Browse files
committed
add semantics to MaybeDangling
1 parent c9147d1 commit 68a92e9

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

compiler/rustc_hir/src/lang_items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ language_item_table! {
353353

354354
PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);
355355

356-
ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::None;
356+
ManuallyDrop, sym::manually_drop, manually_drop, Target::Struct, GenericRequirement::Exact(1);
357+
MaybeDangling, sym::maybe_dangling, maybe_dangling, Target::Struct, GenericRequirement::Exact(1);
357358
BikeshedGuaranteedNoDrop, sym::bikeshed_guaranteed_no_drop, bikeshed_guaranteed_no_drop, Target::Trait, GenericRequirement::Exact(0);
358359

359360
MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None;

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ bitflags::bitflags! {
5959
const IS_PIN = 1 << 11;
6060
/// Indicates whether the type is `#[pin_project]`.
6161
const IS_PIN_PROJECT = 1 << 12;
62+
/// Indicates whether the type is `MaybeDangling<_>`.
63+
const IS_MAYBE_DANGLING = 1 << 13;
6264
}
6365
}
6466
rustc_data_structures::external_bitflags_debug! { AdtFlags }
@@ -315,6 +317,9 @@ impl AdtDefData {
315317
if tcx.is_lang_item(did, LangItem::ManuallyDrop) {
316318
flags |= AdtFlags::IS_MANUALLY_DROP;
317319
}
320+
if tcx.is_lang_item(did, LangItem::MaybeDangling) {
321+
flags |= AdtFlags::IS_MAYBE_DANGLING;
322+
}
318323
if tcx.is_lang_item(did, LangItem::UnsafeCell) {
319324
flags |= AdtFlags::IS_UNSAFE_CELL;
320325
}
@@ -439,6 +444,12 @@ impl<'tcx> AdtDef<'tcx> {
439444
self.flags().contains(AdtFlags::IS_MANUALLY_DROP)
440445
}
441446

447+
/// Returns `true` if this is `MaybeDangling<T>`.
448+
#[inline]
449+
pub fn is_maybe_dangling(self) -> bool {
450+
self.flags().contains(AdtFlags::IS_MAYBE_DANGLING)
451+
}
452+
442453
/// Returns `true` if this is `Pin<T>`.
443454
#[inline]
444455
pub fn is_pin(self) -> bool {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,12 @@ where
10531053
})
10541054
}
10551055

1056+
ty::Adt(adt_def, ..) if adt_def.is_maybe_dangling() => {
1057+
// FIXME: what is the exact effect of maybe dangling?
1058+
Self::ty_and_layout_pointee_info_at(this.field(cx, 0), cx, offset)
1059+
.map(|info| PointeeInfo { safe: None, ..info })
1060+
}
1061+
10561062
_ => {
10571063
let mut data_variant = match &this.variants {
10581064
// Within the discriminant field, only the niche itself is
@@ -1091,7 +1097,7 @@ where
10911097
}
10921098
}
10931099
Variants::Multiple { .. } => None,
1094-
_ => Some(this),
1100+
Variants::Empty | Variants::Single { .. } => Some(this),
10951101
};
10961102

10971103
if let Some(variant) = data_variant

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ symbols! {
14011401
maxnumf128,
14021402
may_dangle,
14031403
may_unwind,
1404+
maybe_dangling,
14041405
maybe_uninit,
14051406
maybe_uninit_uninit,
14061407
maybe_uninit_zeroed,

compiler/rustc_ty_utils/src/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn fn_abi_sanity_check<'tcx>(
472472
fn_arg_sanity_check(cx, fn_abi, spec_abi, &fn_abi.ret);
473473
}
474474

475-
#[tracing::instrument(level = "debug", skip(cx, instance))]
475+
// #[tracing::instrument(level = "debug", skip(cx, instance))]
476476
fn fn_abi_new_uncached<'tcx>(
477477
cx: &LayoutCx<'tcx>,
478478
sig: ty::FnSig<'tcx>,

library/core/src/mem/maybe_dangling.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use crate::{mem, ptr};
5959
#[repr(transparent)]
6060
#[rustc_pub_transparent]
6161
#[derive(Debug, Copy, Clone, Default)]
62+
#[lang = "maybe_dangling"]
6263
pub struct MaybeDangling<P: ?Sized>(P);
6364

6465
impl<P: ?Sized> MaybeDangling<P> {

0 commit comments

Comments
 (0)