File tree Expand file tree Collapse file tree
compiler/rustc_mir_transform/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ;
1213use rustc_hir:: def_id:: LocalDefId ;
1314use rustc_index:: IndexVec ;
1415use 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 }
You can’t perform that action at this time.
0 commit comments