@@ -142,6 +142,7 @@ pub fn provide(providers: &mut Providers) {
142142 is_ctfe_mir_available : |tcx, did| is_mir_available ( tcx, did) ,
143143 mir_callgraph_reachable : inline:: cycle:: mir_callgraph_reachable,
144144 mir_inliner_callees : inline:: cycle:: mir_inliner_callees,
145+ const_prop_lint,
145146 promoted_mir,
146147 deduced_param_attrs : deduce_param_attrs:: deduced_param_attrs,
147148 ..* providers
@@ -394,6 +395,27 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
394395 body
395396}
396397
398+ fn const_prop_lint ( tcx : TyCtxt < ' _ > , def : LocalDefId ) {
399+ let ( body, _) = tcx. mir_promoted ( def) ;
400+ let body = body. borrow ( ) ;
401+
402+ let mir_borrowck = tcx. mir_borrowck ( def) ;
403+
404+ // If there are impossible bounds on the body being const prop linted,
405+ // the const eval logic used in const prop may ICE unexpectedly.
406+ let predicates = tcx
407+ . predicates_of ( body. source . def_id ( ) )
408+ . predicates
409+ . iter ( )
410+ . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
411+ if !traits:: impossible_predicates ( tcx, traits:: elaborate ( tcx, predicates) . collect ( ) )
412+ && mir_borrowck. tainted_by_errors . is_none ( )
413+ && body. tainted_by_errors . is_none ( )
414+ {
415+ const_prop_lint:: ConstPropLint . run_lint ( tcx, & body) ;
416+ }
417+ }
418+
397419/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
398420/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
399421/// end up missing the source MIR due to stealing happening.
@@ -402,6 +424,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
402424 tcx. ensure_with_value ( ) . mir_coroutine_witnesses ( def) ;
403425 }
404426 let mir_borrowck = tcx. mir_borrowck ( def) ;
427+ tcx. ensure ( ) . const_prop_lint ( def) ;
405428
406429 let is_fn_like = tcx. def_kind ( def) . is_fn_like ( ) ;
407430 if is_fn_like {
@@ -534,7 +557,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
534557 & elaborate_box_derefs:: ElaborateBoxDerefs ,
535558 & coroutine:: StateTransform ,
536559 & add_retag:: AddRetag ,
537- & Lint ( const_prop_lint:: ConstPropLint ) ,
538560 ] ;
539561 pm:: run_passes_no_validate ( tcx, body, passes, Some ( MirPhase :: Runtime ( RuntimePhase :: Initial ) ) ) ;
540562}
0 commit comments