Skip to content

Commit 113aeac

Browse files
committed
impl BikeshedGuaranteedNoDrop for MaybeUninit<T>
1 parent c89f2c7 commit 113aeac

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 15 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 `MaybeUninit`.
63+
const IS_MAYBE_UNINIT = 1 << 13;
6264
}
6365
}
6466
rustc_data_structures::external_bitflags_debug! { AdtFlags }
@@ -224,6 +226,10 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
224226
self.is_manually_drop()
225227
}
226228

229+
fn is_maybe_uninit(self) -> bool {
230+
self.is_maybe_uninit()
231+
}
232+
227233
fn all_field_tys(
228234
self,
229235
tcx: TyCtxt<'tcx>,
@@ -315,6 +321,9 @@ impl AdtDefData {
315321
if tcx.is_lang_item(did, LangItem::ManuallyDrop) {
316322
flags |= AdtFlags::IS_MANUALLY_DROP;
317323
}
324+
if tcx.is_lang_item(did, LangItem::MaybeUninit) {
325+
flags |= AdtFlags::IS_MAYBE_UNINIT;
326+
}
318327
if tcx.is_lang_item(did, LangItem::UnsafeCell) {
319328
flags |= AdtFlags::IS_UNSAFE_CELL;
320329
}
@@ -439,6 +448,12 @@ impl<'tcx> AdtDef<'tcx> {
439448
self.flags().contains(AdtFlags::IS_MANUALLY_DROP)
440449
}
441450

451+
/// Returns `true` if this is `ManuallyDrop<T>`.
452+
#[inline]
453+
pub fn is_maybe_uninit(self) -> bool {
454+
self.flags().contains(AdtFlags::IS_MAYBE_UNINIT)
455+
}
456+
442457
/// Returns `true` if this is `Pin<T>`.
443458
#[inline]
444459
pub fn is_pin(self) -> bool {

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,8 @@ where
701701
match ty.kind() {
702702
// `&mut T` and `&T` always implement `BikeshedGuaranteedNoDrop`.
703703
ty::Ref(..) => {}
704-
// `ManuallyDrop<T>` always implements `BikeshedGuaranteedNoDrop`.
705-
ty::Adt(def, _) if def.is_manually_drop() => {}
704+
// `ManuallyDrop<T>` and `MaybeUninit<T>` always implement `BikeshedGuaranteedNoDrop`.
705+
ty::Adt(def, _) if def.is_manually_drop() || def.is_maybe_uninit() => {}
706706
// Arrays and tuples implement `BikeshedGuaranteedNoDrop` only if
707707
// their constituent types implement `BikeshedGuaranteedNoDrop`.
708708
ty::Tuple(tys) => {

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12571257
match *self_ty.skip_binder().kind() {
12581258
// `&mut T` and `&T` always implement `BikeshedGuaranteedNoDrop`.
12591259
ty::Ref(..) => {}
1260-
// `ManuallyDrop<T>` always implements `BikeshedGuaranteedNoDrop`.
1261-
ty::Adt(def, _) if def.is_manually_drop() => {}
1260+
// `ManuallyDrop<T>` and `MaybeUninit<T>` always implement `BikeshedGuaranteedNoDrop`.
1261+
ty::Adt(def, _) if def.is_manually_drop() || def.is_maybe_uninit() => {}
12621262
// Arrays and tuples implement `BikeshedGuaranteedNoDrop` only if
12631263
// their constituent types implement `BikeshedGuaranteedNoDrop`.
12641264
ty::Tuple(tys) => {

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
566566
fn is_phantom_data(self) -> bool;
567567

568568
fn is_manually_drop(self) -> bool;
569+
fn is_maybe_uninit(self) -> bool;
569570

570571
// FIXME: perhaps use `all_fields` and expose `FieldDef`.
571572
fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;

library/core/src/marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ impl<T: PointeeSized> Copy for &T {}
496496
/// Implemented for:
497497
/// * `&T`, `&mut T` for all `T`,
498498
/// * `ManuallyDrop<T>` for all `T`,
499+
/// * `MaybeUninit<T>` for all `T`,
499500
/// * tuples and arrays whose elements implement `BikeshedGuaranteedNoDrop`,
500501
/// * or otherwise, all types that are `Copy`.
501502
///

0 commit comments

Comments
 (0)