Skip to content

Commit 2e301c8

Browse files
committed
Do not ICE when failing to normalize during inlining.
1 parent 9d1aeae commit 2e301c8

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
@@ -157,11 +157,13 @@ impl<'tcx> Inliner<'tcx> {
157157
return Err("optimization fuel exhausted");
158158
}
159159

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

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

@@ -407,14 +409,17 @@ impl<'tcx> Inliner<'tcx> {
407409
if let ty::FnDef(def_id, substs) =
408410
*callsite.callee.subst_mir(self.tcx, &f.literal.ty()).kind()
409411
{
410-
let substs = self.tcx.normalize_erasing_regions(self.param_env, substs);
411-
if let Ok(Some(instance)) =
412-
Instance::resolve(self.tcx, self.param_env, def_id, substs)
412+
if let Ok(substs) =
413+
self.tcx.try_normalize_erasing_regions(self.param_env, substs)
413414
{
414-
if callsite.callee.def_id() == instance.def_id() {
415-
return Err("self-recursion");
416-
} else if self.history.contains(&instance) {
417-
return Err("already inlined");
415+
if let Ok(Some(instance)) =
416+
Instance::resolve(self.tcx, self.param_env, def_id, substs)
417+
{
418+
if callsite.callee.def_id() == instance.def_id() {
419+
return Err("self-recursion");
420+
} else if self.history.contains(&instance) {
421+
return Err("already inlined");
422+
}
418423
}
419424
}
420425
// 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)