@@ -252,8 +252,11 @@ fn mir_promoted<'tcx>(
252252 // Ensure that we compute the `mir_const_qualif` for constants at
253253 // this point, before we steal the mir-const result.
254254 // Also this means promotion can rely on all const checks having been done.
255- let _ = tcx. mir_const_qualif_opt_const_arg ( def) ;
255+ let const_qualifs = tcx. mir_const_qualif_opt_const_arg ( def) ;
256256 let mut body = tcx. mir_const ( def) . steal ( ) ;
257+ if let Some ( error_reported) = const_qualifs. tainted_by_errors {
258+ body. tainted_by_errors = Some ( error_reported) ;
259+ }
257260
258261 let mut required_consts = Vec :: new ( ) ;
259262 let mut required_consts_visitor = RequiredConstsVisitor :: new ( & mut required_consts) ;
@@ -358,13 +361,7 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
358361 return tcx. mir_drops_elaborated_and_const_checked ( def) ;
359362 }
360363
361- // (Mir-)Borrowck uses `mir_promoted`, so we have to force it to
362- // execute before we can steal.
363- if let Some ( param_did) = def. const_param_did {
364- tcx. ensure ( ) . mir_borrowck_const_arg ( ( def. did , param_did) ) ;
365- } else {
366- tcx. ensure ( ) . mir_borrowck ( def. did ) ;
367- }
364+ let mir_borrowck = tcx. mir_borrowck_opt_const_arg ( def) ;
368365
369366 let is_fn_like = tcx. hir ( ) . get_by_def_id ( def. did ) . fn_kind ( ) . is_some ( ) ;
370367 if is_fn_like {
@@ -379,6 +376,9 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
379376
380377 let ( body, _) = tcx. mir_promoted ( def) ;
381378 let mut body = body. steal ( ) ;
379+ if let Some ( error_reported) = mir_borrowck. tainted_by_errors {
380+ body. tainted_by_errors = Some ( error_reported) ;
381+ }
382382
383383 // IMPORTANT
384384 pm:: run_passes ( tcx, & mut body, & [ & remove_false_edges:: RemoveFalseEdges ] ) ;
@@ -544,15 +544,13 @@ fn promoted_mir<'tcx>(
544544 return tcx. arena . alloc ( IndexVec :: new ( ) ) ;
545545 }
546546
547- if let Some ( param_did) = def. const_param_did {
548- tcx. ensure ( ) . mir_borrowck_const_arg ( ( def. did , param_did) ) ;
549- } else {
550- tcx. ensure ( ) . mir_borrowck ( def. did ) ;
551- }
552- let ( _, promoted) = tcx. mir_promoted ( def) ;
553- let mut promoted = promoted. steal ( ) ;
547+ let tainted_by_errors = tcx. mir_borrowck_opt_const_arg ( def) . tainted_by_errors ;
548+ let mut promoted = tcx. mir_promoted ( def) . 1 . steal ( ) ;
554549
555550 for body in & mut promoted {
551+ if let Some ( error_reported) = tainted_by_errors {
552+ body. tainted_by_errors = Some ( error_reported) ;
553+ }
556554 run_post_borrowck_cleanup_passes ( tcx, body) ;
557555 }
558556
0 commit comments