From 85433c4c78fe514a6e9d1780700934c477c2789f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 21 Mar 2024 14:04:10 +0100 Subject: [PATCH] filter required_consts during inlining --- compiler/rustc_middle/src/mir/consts.rs | 5 ++--- compiler/rustc_mir_transform/src/inline.rs | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/mir/consts.rs b/compiler/rustc_middle/src/mir/consts.rs index b01ccecd4846..769d35685227 100644 --- a/compiler/rustc_middle/src/mir/consts.rs +++ b/compiler/rustc_middle/src/mir/consts.rs @@ -245,11 +245,10 @@ impl<'tcx> Const<'tcx> { match self { Const::Ty(c) => match c.kind() { ty::ConstKind::Value(_) => false, // already a value, cannot error - ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => true, // these are errors or could be replaced by errors - _ => bug!("is_required_const: unexpected ty::ConstKind {:#?}", c), + _ => true, }, - Const::Unevaluated(..) => true, Const::Val(..) => false, // already a value, cannot error + Const::Unevaluated(..) => true, } } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 767879706bbf..efd4e1f27019 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -706,8 +706,12 @@ impl<'tcx> Inliner<'tcx> { kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) }, }); - // Copy required constants from the callee_body into the caller_body. - caller_body.required_consts.extend(callee_body.required_consts); + // Copy required constants from the callee_body into the caller_body. Although we are only + // pushing unevaluated consts to `required_consts`, here they may have been evaluated + // because we are calling `instantiate_and_normalize_erasing_regions` -- so we filter again. + caller_body.required_consts.extend( + callee_body.required_consts.into_iter().filter(|ct| ct.const_.is_required_const()), + ); // Now that we incorporated the callee's `required_consts`, we can remove the callee from // `mentioned_items` -- but we have to take their `mentioned_items` in return. This does // some extra work here to save the monomorphization collector work later. It helps a lot,