Skip to content

Commit 2c1d69e

Browse files
committed
Avoid calling tcx.deduced_param_attrs for constants.
1 parent e45bd12 commit 2c1d69e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! after `optimized_mir`! We check for things that are *not* guaranteed to be preserved by MIR
1010
//! transforms, such as which local variables happen to be mutated.
1111
12+
use rustc_hir::ConstContext;
1213
use rustc_hir::def_id::LocalDefId;
1314
use rustc_index::IndexVec;
1415
use rustc_middle::middle::deduced_param_attrs::{DeducedParamAttrs, UsageSummary};
@@ -255,8 +256,16 @@ impl<'tcx> MirPass<'tcx> for RecoverDeducedParamAttrs {
255256
}
256257

257258
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
259+
// Only run this for MIR that has `optimized_mir`.
260+
let ty::InstanceKind::Item(..) = body.source.instance else { return };
261+
let Some(def_id) = body.source.def_id().as_local() else { return };
262+
match tcx.hir_body_const_context(def_id) {
263+
Some(ConstContext::ConstFn) | None => {}
264+
Some(_) => return,
265+
};
266+
258267
// If we deduced nothing, there is no fixup to perform.
259-
let deduced_param_attrs = tcx.deduced_param_attrs(body.source.def_id());
268+
let deduced_param_attrs = tcx.deduced_param_attrs(def_id);
260269
if deduced_param_attrs.is_empty() {
261270
return;
262271
}

0 commit comments

Comments
 (0)