Skip to content

Commit c89ee08

Browse files
Make sure we actually use the right trivial lifetime substs when eagerly monomorphizing drop for structs
1 parent 8361aef commit c89ee08

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

Diff for: compiler/rustc_monomorphize/src/collector.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1410,19 +1410,33 @@ impl<'v> RootCollector<'_, 'v> {
14101410
&& !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
14111411
{
14121412
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
1413+
let id_args =
1414+
ty::GenericArgs::for_item(self.tcx, id.owner_id.to_def_id(), |param, _| {
1415+
match param.kind {
1416+
GenericParamDefKind::Lifetime => {
1417+
self.tcx.lifetimes.re_erased.into()
1418+
}
1419+
GenericParamDefKind::Type { .. }
1420+
| GenericParamDefKind::Const { .. } => {
1421+
unreachable!(
1422+
"`own_requires_monomorphization` check means that \
1423+
we should have no type/const params"
1424+
)
1425+
}
1426+
}
1427+
});
14131428

14141429
// This type is impossible to instantiate, so we should not try to
14151430
// generate a `drop_in_place` instance for it.
14161431
if self.tcx.instantiate_and_check_impossible_predicates((
14171432
id.owner_id.to_def_id(),
1418-
ty::List::empty(),
1433+
id_args,
14191434
)) {
14201435
return;
14211436
}
14221437

1423-
let ty = self.tcx.erase_regions(
1424-
self.tcx.type_of(id.owner_id.to_def_id()).instantiate_identity(),
1425-
);
1438+
let ty =
1439+
self.tcx.type_of(id.owner_id.to_def_id()).instantiate(self.tcx, id_args);
14261440
assert!(!ty.has_non_region_param());
14271441
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
14281442
}

Diff for: compiler/rustc_type_ir/src/binder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
804804
#[inline(never)]
805805
fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
806806
panic!(
807-
"const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
807+
"region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
808808
ebr,
809809
r,
810810
ebr.index(),

Diff for: tests/codegen-units/item-collection/drop-glue-eager.rs

+13
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,16 @@ impl<'a> Drop for StructWithDropAndLt<'a> {
4141
struct StructWithDropAndLt<'a> {
4242
x: &'a i32,
4343
}
44+
45+
// Make sure we don't ICE when checking impossible predicates for the struct.
46+
// Regression test for <https://github.com/rust-lang/rust/issues/135515>.
47+
//~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithLtAndPredicate<'_>> - shim(Some(StructWithLtAndPredicate<'_>))
48+
struct StructWithLtAndPredicate<'a: 'a> {
49+
x: &'a i32,
50+
}
51+
52+
// We should be able to monomorphize drops for struct with lifetimes.
53+
impl<'a> Drop for StructWithLtAndPredicate<'a> {
54+
//~ MONO_ITEM fn <StructWithLtAndPredicate<'_> as std::ops::Drop>::drop
55+
fn drop(&mut self) {}
56+
}

0 commit comments

Comments
 (0)