@@ -142,6 +142,7 @@ pub fn provide(providers: &mut Providers) {
142
142
is_ctfe_mir_available : |tcx, did| is_mir_available ( tcx, did) ,
143
143
mir_callgraph_reachable : inline:: cycle:: mir_callgraph_reachable,
144
144
mir_inliner_callees : inline:: cycle:: mir_inliner_callees,
145
+ const_prop_lint,
145
146
promoted_mir,
146
147
deduced_param_attrs : deduce_param_attrs:: deduced_param_attrs,
147
148
..* providers
@@ -398,6 +399,27 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
398
399
body
399
400
}
400
401
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
+
401
423
/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
402
424
/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
403
425
/// 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) -> &
406
428
tcx. ensure_with_value ( ) . mir_coroutine_witnesses ( def) ;
407
429
}
408
430
let mir_borrowck = tcx. mir_borrowck ( def) ;
431
+ tcx. ensure ( ) . const_prop_lint ( def) ;
409
432
410
433
let is_fn_like = tcx. def_kind ( def) . is_fn_like ( ) ;
411
434
if is_fn_like {
@@ -538,7 +561,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
538
561
& elaborate_box_derefs:: ElaborateBoxDerefs ,
539
562
& coroutine:: StateTransform ,
540
563
& add_retag:: AddRetag ,
541
- & Lint ( const_prop_lint:: ConstPropLint ) ,
542
564
] ;
543
565
pm:: run_passes_no_validate ( tcx, body, passes, Some ( MirPhase :: Runtime ( RuntimePhase :: Initial ) ) ) ;
544
566
}
0 commit comments