diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_mir/src/monomorphize/polymorphize.rs index d4185c063ef..e51c9314595 100644 --- a/compiler/rustc_mir/src/monomorphize/polymorphize.rs +++ b/compiler/rustc_mir/src/monomorphize/polymorphize.rs @@ -56,7 +56,7 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { // Exit early when there is no MIR available. let context = tcx.hir().body_const_context(def_id.expect_local()); match context { - None if !tcx.is_mir_available(def_id) => { + Some(ConstContext::Fn) | None if !tcx.is_mir_available(def_id) => { debug!("unused_generic_params: (no mir available) def_id={:?}", def_id); return FiniteBitSet::new_empty(); } @@ -78,10 +78,9 @@ fn unused_generic_params(tcx: TyCtxt<'_>, def_id: DefId) -> FiniteBitSet { // Visit MIR and accumululate used generic parameters. let body = match context { - None => tcx.optimized_mir(def_id), - // FIXME(oli-obk): since this is solely used for codegen (I think?), should we keep using - // the optimized MIR for `const fn`? Need to adjust the above `is_mir_available` check - // in that case. + // Const functions are actually called and should thus be considered for polymorphization + // via their runtime MIR + Some(ConstContext::Fn) | None => tcx.optimized_mir(def_id), Some(_) => tcx.mir_for_ctfe(def_id), }; let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters: &mut unused_parameters };