Skip to content

Commit 74f0bcc

Browse files
authored
Rollup merge of rust-lang#97696 - cjgillot:normalize-inline, r=compiler-errors
Do not ICE when failing to normalize during inlining. Fixes rust-lang#97695
2 parents 8971235 + 2e301c8 commit 74f0bcc

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

compiler/rustc_mir_transform/src/inline.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ impl<'tcx> Inliner<'tcx> {
158158
return Err("optimization fuel exhausted");
159159
}
160160

161-
let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions(
161+
let Ok(callee_body) = callsite.callee.try_subst_mir_and_normalize_erasing_regions(
162162
self.tcx,
163163
self.param_env,
164164
callee_body.clone(),
165-
);
165+
) else {
166+
return Err("failed to normalize callee body");
167+
};
166168

167169
let old_blocks = caller_body.basic_blocks().next_index();
168170
self.inline_call(caller_body, &callsite, callee_body);
@@ -253,7 +255,7 @@ impl<'tcx> Inliner<'tcx> {
253255
let func_ty = func.ty(caller_body, self.tcx);
254256
if let ty::FnDef(def_id, substs) = *func_ty.kind() {
255257
// To resolve an instance its substs have to be fully normalized.
256-
let substs = self.tcx.normalize_erasing_regions(self.param_env, substs);
258+
let substs = self.tcx.try_normalize_erasing_regions(self.param_env, substs).ok()?;
257259
let callee =
258260
Instance::resolve(self.tcx, self.param_env, def_id, substs).ok().flatten()?;
259261

@@ -408,14 +410,17 @@ impl<'tcx> Inliner<'tcx> {
408410
if let ty::FnDef(def_id, substs) =
409411
*callsite.callee.subst_mir(self.tcx, &f.literal.ty()).kind()
410412
{
411-
let substs = self.tcx.normalize_erasing_regions(self.param_env, substs);
412-
if let Ok(Some(instance)) =
413-
Instance::resolve(self.tcx, self.param_env, def_id, substs)
413+
if let Ok(substs) =
414+
self.tcx.try_normalize_erasing_regions(self.param_env, substs)
414415
{
415-
if callsite.callee.def_id() == instance.def_id() {
416-
return Err("self-recursion");
417-
} else if self.history.contains(&instance) {
418-
return Err("already inlined");
416+
if let Ok(Some(instance)) =
417+
Instance::resolve(self.tcx, self.param_env, def_id, substs)
418+
{
419+
if callsite.callee.def_id() == instance.def_id() {
420+
return Err("self-recursion");
421+
} else if self.history.contains(&instance) {
422+
return Err("already inlined");
423+
}
419424
}
420425
}
421426
// Don't give intrinsics the extra penalty for calls
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Zinline-mir --emit=mir
2+
// build-pass
3+
4+
pub trait Associate {
5+
type Associated;
6+
}
7+
8+
pub struct Wrap<'a> {
9+
pub field: &'a i32,
10+
}
11+
12+
pub trait Create<T> {
13+
fn create() -> Self;
14+
}
15+
16+
pub fn oh_no<'a, T>()
17+
where
18+
Wrap<'a>: Associate,
19+
<Wrap<'a> as Associate>::Associated: Create<T>,
20+
{
21+
<Wrap<'a> as Associate>::Associated::create();
22+
}
23+
24+
pub fn main() {}

0 commit comments

Comments
 (0)