@@ -23,7 +23,6 @@ use rustc_data_structures::graph::dominators::Dominators;
2323use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed } ;
2424use rustc_hir as hir;
2525use rustc_hir:: def_id:: LocalDefId ;
26- use rustc_hir:: Node ;
2726use rustc_index:: bit_set:: ChunkedBitSet ;
2827use rustc_index:: vec:: IndexVec ;
2928use rustc_infer:: infer:: { InferCtxt , TyCtxtInferExt } ;
@@ -288,14 +287,16 @@ fn do_mir_borrowck<'a, 'tcx>(
288287 . pass_name ( "borrowck" )
289288 . iterate_to_fixpoint ( ) ;
290289
291- let def_hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
292- let movable_generator = !matches ! (
293- tcx. hir( ) . get( def_hir_id) ,
294- Node :: Expr ( & hir:: Expr {
295- kind: hir:: ExprKind :: Closure ( .., Some ( hir:: Movability :: Static ) ) ,
296- ..
297- } )
298- ) ;
290+ let movable_generator =
291+ // The first argument is the generator type passed by value
292+ if let Some ( local) = body. local_decls . raw . get ( 1 )
293+ // Get the interior types and substs which typeck computed
294+ && let ty:: Generator ( _, _, hir:: Movability :: Static ) = local. ty . kind ( )
295+ {
296+ false
297+ } else {
298+ true
299+ } ;
299300
300301 for ( idx, move_data_results) in promoted_errors {
301302 let promoted_body = & promoted[ idx] ;
@@ -385,7 +386,7 @@ fn do_mir_borrowck<'a, 'tcx>(
385386 let scope = mbcx. body . source_info ( location) . scope ;
386387 let lint_root = match & mbcx. body . source_scopes [ scope] . local_data {
387388 ClearCrossCrate :: Set ( data) => data. lint_root ,
388- _ => def_hir_id ,
389+ _ => tcx . hir ( ) . local_def_id_to_hir_id ( def . did ) ,
389390 } ;
390391
391392 // Span and message don't matter; we overwrite them below anyway
0 commit comments