@@ -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
@@ -398,6 +399,27 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
398399 body
399400}
400401
402+ fn const_prop_lint ( tcx : TyCtxt < ' _ > , def : LocalDefId ) {
403+ let ( body, _) = tcx. mir_promoted ( def) ;
404+ let body = body. borrow ( ) ;
405+
406+ let mir_borrowck = tcx. mir_borrowck ( def) ;
407+
408+ // If there are impossible bounds on the body being const prop linted,
409+ // the const eval logic used in const prop may ICE unexpectedly.
410+ let predicates = tcx
411+ . predicates_of ( body. source . def_id ( ) )
412+ . predicates
413+ . iter ( )
414+ . filter_map ( |( p, _) | if p. is_global ( ) { Some ( * p) } else { None } ) ;
415+ if !traits:: impossible_predicates ( tcx, traits:: elaborate ( tcx, predicates) . collect ( ) )
416+ && mir_borrowck. tainted_by_errors . is_none ( )
417+ && body. tainted_by_errors . is_none ( )
418+ {
419+ const_prop_lint:: ConstPropLint . run_lint ( tcx, & body) ;
420+ }
421+ }
422+
401423/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
402424/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
403425/// end up missing the source MIR due to stealing happening.
@@ -406,6 +428,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
406428 tcx. ensure_with_value ( ) . mir_coroutine_witnesses ( def) ;
407429 }
408430 let mir_borrowck = tcx. mir_borrowck ( def) ;
431+ tcx. ensure ( ) . const_prop_lint ( def) ;
409432
410433 let is_fn_like = tcx. def_kind ( def) . is_fn_like ( ) ;
411434 if is_fn_like {
@@ -538,7 +561,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
538561 & elaborate_box_derefs:: ElaborateBoxDerefs ,
539562 & coroutine:: StateTransform ,
540563 & add_retag:: AddRetag ,
541- & Lint ( const_prop_lint:: ConstPropLint ) ,
542564 ] ;
543565 pm:: run_passes_no_validate ( tcx, body, passes, Some ( MirPhase :: Runtime ( RuntimePhase :: Initial ) ) ) ;
544566}
0 commit comments