Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we actually use the right trivial lifetime substs when eagerly monomorphizing drop for ADTs #135520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1410,19 +1410,33 @@ impl<'v> RootCollector<'_, 'v> {
&& !self.tcx.generics_of(id.owner_id).requires_monomorphization(self.tcx)
{
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
let id_args =
ty::GenericArgs::for_item(self.tcx, id.owner_id.to_def_id(), |param, _| {
match param.kind {
GenericParamDefKind::Lifetime => {
self.tcx.lifetimes.re_erased.into()
}
GenericParamDefKind::Type { .. }
| GenericParamDefKind::Const { .. } => {
unreachable!(
"`own_requires_monomorphization` check means that \
we should have no type/const params"
)
}
}
});

// This type is impossible to instantiate, so we should not try to
// generate a `drop_in_place` instance for it.
if self.tcx.instantiate_and_check_impossible_predicates((
id.owner_id.to_def_id(),
ty::List::empty(),
id_args,
)) {
return;
}

let ty = self.tcx.erase_regions(
self.tcx.type_of(id.owner_id.to_def_id()).instantiate_identity(),
);
let ty =
self.tcx.type_of(id.owner_id.to_def_id()).instantiate(self.tcx, id_args);
assert!(!ty.has_non_region_param());
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> {
#[inline(never)]
fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! {
panic!(
"const parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
"region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}",
ebr,
r,
ebr.index(),
Expand Down
13 changes: 13 additions & 0 deletions tests/codegen-units/item-collection/drop-glue-eager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ impl<'a> Drop for StructWithDropAndLt<'a> {
struct StructWithDropAndLt<'a> {
x: &'a i32,
}

// Make sure we don't ICE when checking impossible predicates for the struct.
// Regression test for <https://github.com/rust-lang/rust/issues/135515>.
//~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithLtAndPredicate<'_>> - shim(Some(StructWithLtAndPredicate<'_>))
struct StructWithLtAndPredicate<'a: 'a> {
x: &'a i32,
}

// We should be able to monomorphize drops for struct with lifetimes.
impl<'a> Drop for StructWithLtAndPredicate<'a> {
//~ MONO_ITEM fn <StructWithLtAndPredicate<'_> as std::ops::Drop>::drop
fn drop(&mut self) {}
}
Loading