@@ -16,6 +16,7 @@ use rustc_data_structures::indexed_vec::Idx;
16
16
use syntax_pos:: Span ;
17
17
18
18
use borrow_check:: MirBorrowckCtxt ;
19
+ use borrow_check:: prefixes:: PrefixSet ;
19
20
use dataflow:: move_paths:: { IllegalMoveOrigin , IllegalMoveOriginKind } ;
20
21
use dataflow:: move_paths:: { LookupResult , MoveError , MovePathIndex } ;
21
22
use util:: borrowck_errors:: { BorrowckErrors , Origin } ;
@@ -254,15 +255,16 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
254
255
// borrow to provide feedback about why this
255
256
// was a move rather than a copy.
256
257
let ty = place. ty ( self . mir , self . tcx ) . to_ty ( self . tcx ) ;
258
+ let is_upvar_field_projection =
259
+ self . prefixes ( & original_path, PrefixSet :: All )
260
+ . any ( |p| p. is_upvar_field_projection ( self . mir , & self . tcx )
261
+ . is_some ( ) ) ;
257
262
match ty. sty {
258
263
ty:: TyArray ( ..) | ty:: TySlice ( ..) => self
259
264
. tcx
260
265
. cannot_move_out_of_interior_noncopy ( span, ty, None , origin) ,
261
266
ty:: TyClosure ( def_id, closure_substs)
262
- if !self . mir . upvar_decls . is_empty ( ) &&
263
- original_path. strip_deref_projections ( )
264
- . is_upvar_field_projection ( self . mir , & self . tcx )
265
- . is_some ( )
267
+ if !self . mir . upvar_decls . is_empty ( ) && is_upvar_field_projection
266
268
=> {
267
269
let closure_kind_ty =
268
270
closure_substs. closure_kind_ty ( def_id, self . tcx ) ;
@@ -286,13 +288,18 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
286
288
let mut diag = self . tcx . cannot_move_out_of (
287
289
span, place_description, origin) ;
288
290
289
- if let Some ( field) = original_path. is_upvar_field_projection (
290
- self . mir , & self . tcx ) {
291
- let upvar_decl = & self . mir . upvar_decls [ field. index ( ) ] ;
292
- let upvar_hir_id = upvar_decl. var_hir_id . assert_crate_local ( ) ;
293
- let upvar_node_id = self . tcx . hir . hir_to_node_id ( upvar_hir_id) ;
294
- let upvar_span = self . tcx . hir . span ( upvar_node_id) ;
295
- diag. span_label ( upvar_span, "captured outer variable" ) ;
291
+ for prefix in self . prefixes ( & original_path, PrefixSet :: All ) {
292
+ if let Some ( field) = prefix. is_upvar_field_projection (
293
+ self . mir , & self . tcx ) {
294
+ let upvar_decl = & self . mir . upvar_decls [ field. index ( ) ] ;
295
+ let upvar_hir_id =
296
+ upvar_decl. var_hir_id . assert_crate_local ( ) ;
297
+ let upvar_node_id =
298
+ self . tcx . hir . hir_to_node_id ( upvar_hir_id) ;
299
+ let upvar_span = self . tcx . hir . span ( upvar_node_id) ;
300
+ diag. span_label ( upvar_span, "captured outer variable" ) ;
301
+ break ;
302
+ }
296
303
}
297
304
298
305
diag
0 commit comments