Skip to content

Commit 23a8d54

Browse files
committed
Avoid calling tcx.deduced_param_attrs for constants.
1 parent 76f36dd commit 23a8d54

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,16 @@ impl<'tcx> MirPass<'tcx> for RecoverDeducedParamAttrs {
262262
}
263263

264264
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
265+
// Only run this for MIR that has `optimized_mir`.
266+
let ty::InstanceKind::Item(..) = body.source.instance else { return };
267+
let Some(def_id) = body.source.def_id().as_local() else { return };
268+
match tcx.hir_body_const_context(def_id) {
269+
Some(hir::ConstContext::ConstFn) | None => {}
270+
Some(_) => return,
271+
};
272+
265273
// If we deduced nothing, there is no fixup to perform.
266-
let deduced_param_attrs = tcx.deduced_param_attrs(body.source.def_id());
274+
let deduced_param_attrs = tcx.deduced_param_attrs(def_id);
267275
if deduced_param_attrs.is_empty() {
268276
return;
269277
}

0 commit comments

Comments
 (0)