Rollup merge of #135520 - compiler-errors:mono-impossible-drop-with-lifetimes, r=BoxyUwU
Make sure we actually use the right trivial lifetime substs when eagerly monomorphizing drop for ADTs Absolutely clueless mistake of mine. Whoops. When eagerly collecting mono items, when we encounter an ADT, we try to monomorphize its drop glue. In #135313, I made it so that this acts more like eagerly monomorphizing functions, where we allow (in this case) ADTs with lifetimes, since those can be erased by codegen. However, I did not account for the call to `instantiate_and_check_impossible_predicates`, which was still passing an empty set of args. This means that if the ADT in question had any predicates, we'd get an index out of bounds panic. This PR creates the correct set of args for the ADT. Fixes #135515. I assume that this manifests in that issue because of `-Clink-dead-code` or something.
This commit is contained in:
commit
8e91327e71
3 changed files with 32 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue