@@ -7,6 +7,7 @@ use syntax_pos::Span;
7
7
8
8
use crate :: borrow_check:: MirBorrowckCtxt ;
9
9
use crate :: borrow_check:: prefixes:: PrefixSet ;
10
+ use crate :: borrow_check:: error_reporting:: UseSpans ;
10
11
use crate :: dataflow:: move_paths:: {
11
12
IllegalMoveOrigin , IllegalMoveOriginKind , InitLocation ,
12
13
LookupResult , MoveError , MovePathIndex ,
@@ -49,7 +50,7 @@ enum GroupedMoveError<'tcx> {
49
50
// Everything that isn't from pattern matching.
50
51
OtherIllegalMove {
51
52
original_path : Place < ' tcx > ,
52
- span : Span ,
53
+ use_spans : UseSpans ,
53
54
kind : IllegalMoveOriginKind < ' tcx > ,
54
55
} ,
55
56
}
@@ -150,7 +151,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
150
151
MoveError :: IllegalMove {
151
152
cannot_move_out_of : IllegalMoveOrigin { location, kind } ,
152
153
} => {
153
- let stmt_source_info = self . mir . source_info ( location) ;
154
154
// Note: that the only time we assign a place isn't a temporary
155
155
// to a user variable is when initializing it.
156
156
// If that ever stops being the case, then the ever initialized
@@ -178,6 +178,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
178
178
pat_span : _,
179
179
} ) ) ) = local_decl. is_user_variable
180
180
{
181
+ let stmt_source_info = self . mir . source_info ( location) ;
181
182
self . append_binding_error (
182
183
grouped_errors,
183
184
kind,
@@ -191,8 +192,10 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
191
192
return ;
192
193
}
193
194
}
195
+
196
+ let move_spans = self . move_spans ( & original_path, location) ;
194
197
grouped_errors. push ( GroupedMoveError :: OtherIllegalMove {
195
- span : stmt_source_info . span ,
198
+ use_spans : move_spans ,
196
199
original_path,
197
200
kind,
198
201
} ) ;
@@ -288,9 +291,15 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
288
291
let ( span, original_path, kind) : ( Span , & Place < ' tcx > , & IllegalMoveOriginKind < ' _ > ) =
289
292
match error {
290
293
GroupedMoveError :: MovesFromPlace { span, ref original_path, ref kind, .. } |
291
- GroupedMoveError :: MovesFromValue { span, ref original_path, ref kind, .. } |
292
- GroupedMoveError :: OtherIllegalMove { span, ref original_path, ref kind } => {
294
+ GroupedMoveError :: MovesFromValue { span, ref original_path, ref kind, .. } => {
293
295
( span, original_path, kind)
296
+ }
297
+ GroupedMoveError :: OtherIllegalMove {
298
+ use_spans,
299
+ ref original_path,
300
+ ref kind
301
+ } => {
302
+ ( use_spans. args_or_use ( ) , original_path, kind)
294
303
} ,
295
304
} ;
296
305
debug ! ( "report: original_path={:?} span={:?}, kind={:?} \
@@ -548,7 +557,8 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
548
557
self . add_move_error_details ( err, & binds_to) ;
549
558
}
550
559
// No binding. Nothing to suggest.
551
- GroupedMoveError :: OtherIllegalMove { ref original_path, span, .. } => {
560
+ GroupedMoveError :: OtherIllegalMove { ref original_path, use_spans, .. } => {
561
+ let span = use_spans. var_or_use ( ) ;
552
562
let place_ty = original_path. ty ( self . mir , self . infcx . tcx ) . ty ;
553
563
let place_desc = match self . describe_place ( original_path) {
554
564
Some ( desc) => format ! ( "`{}`" , desc) ,
@@ -560,6 +570,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
560
570
place_ty,
561
571
Some ( span) ,
562
572
) ;
573
+
574
+ use_spans. args_span_label ( err, format ! ( "move out of {} occurs here" , place_desc) ) ;
575
+ use_spans. var_span_label (
576
+ err,
577
+ format ! ( "move occurs due to use{}" , use_spans. describe( ) ) ,
578
+ ) ;
563
579
} ,
564
580
}
565
581
}
0 commit comments