@@ -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
@@ -394,6 +395,27 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
394
395
body
395
396
}
396
397
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
+
397
419
/// Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs
398
420
/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
399
421
/// 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) -> &
402
424
tcx. ensure_with_value ( ) . mir_coroutine_witnesses ( def) ;
403
425
}
404
426
let mir_borrowck = tcx. mir_borrowck ( def) ;
427
+ tcx. ensure ( ) . const_prop_lint ( def) ;
405
428
406
429
let is_fn_like = tcx. def_kind ( def) . is_fn_like ( ) ;
407
430
if is_fn_like {
@@ -534,7 +557,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
534
557
& elaborate_box_derefs:: ElaborateBoxDerefs ,
535
558
& coroutine:: StateTransform ,
536
559
& add_retag:: AddRetag ,
537
- & Lint ( const_prop_lint:: ConstPropLint ) ,
538
560
] ;
539
561
pm:: run_passes_no_validate ( tcx, body, passes, Some ( MirPhase :: Runtime ( RuntimePhase :: Initial ) ) ) ;
540
562
}
0 commit comments