Only call generics_of query in should_encode_mir when necessary

This commit is contained in:
bjorn3 2026-02-04 11:23:29 +00:00
parent 1e6f7845ed
commit 05921d41e9

View file

@ -1113,11 +1113,10 @@ fn should_encode_mir(
DefKind::SyntheticCoroutineBody => (false, true),
// Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id);
let opt = tcx.sess.opts.unstable_opts.always_encode_mir
|| (tcx.sess.opts.output_types.should_codegen()
&& reachable_set.contains(&def_id)
&& (generics.requires_monomorphization(tcx)
&& (tcx.generics_of(def_id).requires_monomorphization(tcx)
|| tcx.cross_crate_inlinable(def_id)));
// The function has a `const` modifier or is in a `const trait`.
let is_const_fn = tcx.is_const_fn(def_id.to_def_id());