Change:
debug!("    final inline threshold = {}", threshold); // FIXME: Give a bonus to functions with only a single caller <del> let mut first_block = true; let mut cost = 0; </del> <ins> let diverges = matches!( callee_body.basic_blocks()[START_BLOCK].terminator().kind, TerminatorKind::Unreachable | TerminatorKind::Call { target: None, .. } ); if diverges && !matches!(callee_attrs.inline, InlineAttr::Always) { return Err("callee diverges unconditionally"); } let mut checker = CostChecker { tcx: self.tcx, param_env: self.param_env, instance: callsite.callee, callee_body, cost: 0, validation: Ok(()), }; </ins> <del> // Traverse the MIR manually so we can account for the effects of // inlining on the CFG. </del> <ins> // Traverse the MIR manually so we can account for the effects of inlining on the CFG. </ins> let mut work_list = vec![START_BLOCK]; let mut visited = BitSet::new_empty(callee_body.basic_blocks().len()); while let Some(bb) = work_list.pop() { if !visited.insert(bb.index()) { continue; } let blk = &callee_body.basic_blocks()[bb]; <ins> checker.visit_basic_block_data(bb, blk); </ins> <del> for stmt in &blk.statements { // Don't count StorageLive/StorageDead in the inlining cost. match stmt.kind { StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Deinit(_) | StatementKind::Nop => {} _ => cost += INSTR_COST, } } </del> let term = blk.terminator(); <del> let mut is_drop = false; match term.kind { TerminatorKind::Drop { ref place, target, unwind } | TerminatorKind::DropAndReplace { ref place, target, unwind, .. } => { is_drop = true; work_list.push(target); // If the place doesn't actually need dropping, treat it like // a regular goto. let ty = callsite.callee.subst_mir(self.tcx, &place.ty(callee_body, tcx).ty); if ty.needs_drop(tcx, self.param_env) { cost += CALL_PENALTY; if let Some(unwind) = unwind { cost += LANDINGPAD_PENALTY; work_list.push(unwind); } } else { cost += INSTR_COST; } } TerminatorKind::Unreachable | TerminatorKind::Call { target: None, .. } if first_block => { // If the function always diverges, don't inline // unless the cost is zero threshold = 0; } TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => { if let ty::FnDef(def_id, _) = *callsite.callee.subst_mir(self.tcx, &f.literal.ty()).kind() { // Don't give intrinsics the extra penalty for calls if tcx.is_intrinsic(def_id) { cost += INSTR_COST; } else { cost += CALL_PENALTY; } } else { cost += CALL_PENALTY; } if cleanup.is_some() { cost += LANDINGPAD_PENALTY; } } TerminatorKind::Assert { cleanup, .. } => { cost += CALL_PENALTY; if cleanup.is_some() { cost += LANDINGPAD_PENALTY; } } TerminatorKind::Resume => cost += RESUME_PENALTY, TerminatorKind::InlineAsm { cleanup, .. } => { cost += INSTR_COST; </del> <ins> if let TerminatorKind::Drop { ref place, target, unwind } | TerminatorKind::DropAndReplace { ref place, target, unwind, .. } = term.kind { work_list.push(target); </ins> <del> if cleanup.is_some() { cost += LANDINGPAD_PENALTY; </del> <ins> // If the place doesn't actually need dropping, treat it like a regular goto. let ty = callsite.callee.subst_mir(self.tcx, &place.ty(callee_body, tcx).ty); if ty.needs_drop(tcx, self.param_env) && let Some(unwind) = unwind { work_list.push(unwind); </ins> } <del> } _ => cost += INSTR_COST, } if !is_drop { for succ in term.successors() { work_list.push(succ); } </del> <ins> } else { work_list.extend(term.successors()) </ins> } <del> first_block = false; </del> } // Count up the cost of local variables and temps, if we know the size // use that, otherwise we use a moderately-large dummy cost. <del> let ptr_size = tcx.data_layout.pointer_size.bytes(); </del> for v in callee_body.vars_and_temps_iter() { <del> let ty = callsite.callee.subst_mir(self.tcx, &callee_body.local_decls[v].ty); // Cost of the var is the size in machine-words, if we know // it. if let Some(size) = type_size_of(tcx, self.param_env, ty) { cost += ((size + ptr_size - 1) / ptr_size) as usize; } else { cost += UNKNOWN_SIZE_COST; } </del> <ins> checker.visit_local_decl(v, &callee_body.local_decls[v]); </ins> } <ins> // Abort if type validation found anything fishy. checker.validation?; let cost = checker.cost; </ins> if let InlineAttr::Always = callee_attrs.inline { debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost); Ok(())

Discussion:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --ICE is triggered when building in file in release mode. I'm not able to reproduce when building in debug mode. In my situation, the crate is built as part of the dependency tree for a binary crate. <!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details
cc this seems like those mir-inliner bugs :thinking:
Bisected to which is likely (similar as issues and ).
Saw a couple of these in Crater, though typically with some other ICEs too (which is why I didn't file bugs). But tagging as 1.64 and beta regression.
For the record, that PR probably revealed this bug but is likely not the cause of it.
Indeed, that's the "usual" normalization failure ICE we have with the MIR inliner. When enabling the MIR inliner, I only a check that we don't have such type mismatch at the signature, but I did not attempt to check all types that appear in the MIR for such mismatch. If we want to fully avoid this ICE, we'd need to fully visit the callee body to check for those type mismatches. do you know if progress has been made on the normalization front?
Hmm, maybe this is fixed by , but I don't have time to investigate this right now. Edit: It's not fixed.
Do you think it may make sense to disable the MIR inliner on beta to give it some more time to bake? I think it was switched on mid-cycle in 1.64, right?
I qualify this as a bug in type normalization that MIR validation exposes. It's not a bug in the MIR inliner.

There are 3 ways to address this: more exceptions to the MIR inliner to avoid those bugs (easy but cumbersome, ); type normalization (very hard); MIR validation (tentative in ); validating MIR in released compilers but keep doing it on tests (very easy). However, I don't think that disabling the MIR inliner will help.
Stopping to validate MIR sounds like a really bad idea to me. MIR validation (in released compilers) has caught many critical issues already like (I found it while investigating a MIR validation failure that someone found in the wild because the mir typeck found something typeck let through) and the most recent let_chains problem which was also found because of a MIR validation ICE.
WG-prioritization assigning priority (). label -I-prioritize +P-critical
Reduced example: label S-bug-has-mcve
Weird, this one crashes with but I couldn't get this to trigger with just mir-opt-levels :thinking: