Skip to content

Commit 1a8eae1

Browse files
zetanumbersoli-obk
andcommitted
Apply suggestions from oli-obk's review
Co-authored-by: Oli Scherer <[email protected]>
1 parent af10880 commit 1a8eae1

File tree

2 files changed

+15
-34
lines changed

2 files changed

+15
-34
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,16 @@ fn upstream_drop_glue_for_provider<'tcx>(
470470
tcx: TyCtxt<'tcx>,
471471
args: GenericArgsRef<'tcx>,
472472
) -> Option<CrateNum> {
473-
if let Some(def_id) = tcx.lang_items().drop_in_place_fn() {
474-
tcx.upstream_monomorphizations_for(def_id).and_then(|monos| monos.get(&args).cloned())
475-
} else {
476-
None
477-
}
473+
let def_id = tcx.lang_items().drop_in_place_fn()?;
474+
tcx.upstream_monomorphizations_for(def_id)?.get(&args).cloned()
478475
}
479476

480477
fn upstream_async_drop_glue_for_provider<'tcx>(
481478
tcx: TyCtxt<'tcx>,
482479
args: GenericArgsRef<'tcx>,
483480
) -> Option<CrateNum> {
484-
if let Some(def_id) = tcx.lang_items().async_drop_in_place_fn() {
485-
tcx.upstream_monomorphizations_for(def_id).and_then(|monos| monos.get(&args).cloned())
486-
} else {
487-
None
488-
}
481+
let def_id = tcx.lang_items().async_drop_in_place_fn()?;
482+
tcx.upstream_monomorphizations_for(def_id)?.get(&args).cloned()
489483
}
490484

491485
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {

compiler/rustc_middle/src/ty/instance.rs

+11-24
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ impl<'tcx> InstanceKind<'tcx> {
314314
if self.requires_inline(tcx) {
315315
return true;
316316
}
317-
if let ty::InstanceKind::DropGlue(.., Some(ty)) = *self {
317+
if let ty::InstanceKind::DropGlue(.., Some(ty))
318+
| ty::InstanceKind::AsyncDropGlueCtorShim(.., Some(ty)) = *self
319+
{
318320
// Drop glue generally wants to be instantiated at every codegen
319321
// unit, but without an #[inline] hint. We should make this
320322
// available to normal end-users.
@@ -329,29 +331,14 @@ impl<'tcx> InstanceKind<'tcx> {
329331
// drops of `Option::None` before LTO. We also respect the intent of
330332
// `#[inline]` on `Drop::drop` implementations.
331333
return ty.ty_adt_def().map_or(true, |adt_def| {
332-
adt_def
333-
.destructor(tcx)
334-
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.did))
335-
});
336-
}
337-
if let ty::InstanceKind::AsyncDropGlueCtorShim(.., Some(ty)) = *self {
338-
// Async drop glue generally wants to be instantiated at
339-
// every codegen unit, but without an #[inline] hint. We
340-
// should make this available to normal end-users.
341-
if tcx.sess.opts.incremental.is_none() {
342-
return true;
343-
}
344-
// When compiling with incremental, we can generate a *lot* of
345-
// codegen units. Including drop glue into all of them has a
346-
// considerable compile time cost.
347-
//
348-
// We include enums without destructors to allow, say, optimizing
349-
// drops of `Option::None` before LTO. We also respect the intent of
350-
// `#[inline]` on `Drop::drop` implementations.
351-
return ty.ty_adt_def().map_or(true, |adt_def| {
352-
adt_def
353-
.async_destructor(tcx)
354-
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.ctor))
334+
match *self {
335+
ty::InstanceKind::DropGlue(..) => adt_def.destructor(tcx).map(|dtor| dtor.did),
336+
ty::InstanceKind::AsyncDropGlueCtorShim(..) => {
337+
adt_def.async_destructor(tcx).map(|dtor| dtor.ctor)
338+
}
339+
_ => unreachable!(),
340+
}
341+
.map_or_else(|| adt_def.is_enum(), |did| tcx.cross_crate_inlinable(did))
355342
});
356343
}
357344
if let ty::InstanceKind::ThreadLocalShim(..) = *self {

0 commit comments

Comments
 (0)