diff options
| author | Aman Arora <me@aman-arora.com> | 2021-09-22 05:17:30 -0400 |
|---|---|---|
| committer | Aman Arora <me@aman-arora.com> | 2021-09-22 05:17:30 -0400 |
| commit | 994793faabba1c490d108504b428ac653433ae44 (patch) | |
| tree | 24e6c24c89287efbc64530e41c6589cb4d84c9a7 /compiler | |
| parent | d2cbe217566de4c95685316c7d59aa2823868a53 (diff) | |
| download | rust-994793faabba1c490d108504b428ac653433ae44.tar.gz rust-994793faabba1c490d108504b428ac653433ae44.zip | |
PR fixup
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ty_utils/src/needs_drop.rs | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 039cbaf4982..98415a84c56 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -240,13 +240,22 @@ fn adt_significant_drop_tys( def_id: DefId, ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { let adt_has_dtor = |adt_def: &ty::AdtDef| { - adt_def.destructor(tcx).map(|dtor| { - if tcx.has_attr(dtor.did, sym::rustc_insignificant_dtor) { - DtorType::Insignificant - } else { - DtorType::Significant - } - }) + let is_marked_insig = tcx.has_attr(adt_def.did, sym::rustc_insignificant_dtor); + if is_marked_insig { + // In some cases like `std::collections::HashMap` where the struct is a wrapper around + // a type that is a Drop type, and the wrapped type (eg: `hashbrown::HashMap`) lies + // outside stdlib, we might choose to still annotate the the wrapper (std HashMap) with + // `rustc_insignificant_dtor`, even if the type itself doesn't have a `Drop` impl. + Some(DtorType::Insignificant) + } else if adt_def.destructor(tcx).is_some() { + // There is a Drop impl and the type isn't marked insignificant, therefore Drop must be + // significant. + Some(DtorType::Significant) + } else { + // No destructor found nor the type is annotated with `rustc_insignificant_dtor`, we + // treat this as the simple case of Drop impl for type. + None + } }; adt_drop_tys_helper(tcx, def_id, adt_has_dtor) } |
