@@ -346,7 +346,33 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
346
346
mbcx. errors_buffer . sort_by_key ( |diag| diag. span . primary_span ( ) ) ;
347
347
348
348
if tcx. migrate_borrowck ( ) {
349
- match tcx. borrowck ( def_id) . signalled_any_error {
349
+ // When borrowck=migrate, check if AST-borrowck would
350
+ // error on the given code.
351
+
352
+ // rust-lang/rust#55492: loop over parents to ensure that
353
+ // errors that AST-borrowck only detects in some parent of
354
+ // a closure still allows NLL to signal an error.
355
+ let mut curr_def_id = def_id;
356
+ let signalled_any_error = loop {
357
+ match tcx. borrowck ( curr_def_id) . signalled_any_error {
358
+ SignalledError :: NoErrorsSeen => {
359
+ // keep traversing (and borrow-checking) parents
360
+ }
361
+ SignalledError :: SawSomeError => {
362
+ // stop search here
363
+ break SignalledError :: SawSomeError ;
364
+ }
365
+ }
366
+
367
+ if tcx. is_closure ( curr_def_id) {
368
+ curr_def_id = tcx. parent_def_id ( curr_def_id)
369
+ . expect ( "a closure must have a parent_def_id" ) ;
370
+ } else {
371
+ break SignalledError :: NoErrorsSeen ;
372
+ }
373
+ } ;
374
+
375
+ match signalled_any_error {
350
376
SignalledError :: NoErrorsSeen => {
351
377
// if AST-borrowck signalled no errors, then
352
378
// downgrade all the buffered MIR-borrowck errors
0 commit comments