Skip to content

Commit 9336b3d

Browse files
committed
Use UseSpans in cannot move errors
1 parent f7e86a5 commit 9336b3d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/librustc_mir/borrow_check/move_errors.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use syntax_pos::Span;
77

88
use crate::borrow_check::MirBorrowckCtxt;
99
use crate::borrow_check::prefixes::PrefixSet;
10+
use crate::borrow_check::error_reporting::UseSpans;
1011
use crate::dataflow::move_paths::{
1112
IllegalMoveOrigin, IllegalMoveOriginKind, InitLocation,
1213
LookupResult, MoveError, MovePathIndex,
@@ -49,7 +50,7 @@ enum GroupedMoveError<'tcx> {
4950
// Everything that isn't from pattern matching.
5051
OtherIllegalMove {
5152
original_path: Place<'tcx>,
52-
span: Span,
53+
use_spans: UseSpans,
5354
kind: IllegalMoveOriginKind<'tcx>,
5455
},
5556
}
@@ -150,7 +151,6 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
150151
MoveError::IllegalMove {
151152
cannot_move_out_of: IllegalMoveOrigin { location, kind },
152153
} => {
153-
let stmt_source_info = self.mir.source_info(location);
154154
// Note: that the only time we assign a place isn't a temporary
155155
// to a user variable is when initializing it.
156156
// If that ever stops being the case, then the ever initialized
@@ -178,6 +178,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
178178
pat_span: _,
179179
}))) = local_decl.is_user_variable
180180
{
181+
let stmt_source_info = self.mir.source_info(location);
181182
self.append_binding_error(
182183
grouped_errors,
183184
kind,
@@ -191,8 +192,10 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
191192
return;
192193
}
193194
}
195+
196+
let move_spans = self.move_spans(&original_path, location);
194197
grouped_errors.push(GroupedMoveError::OtherIllegalMove {
195-
span: stmt_source_info.span,
198+
use_spans: move_spans,
196199
original_path,
197200
kind,
198201
});
@@ -288,9 +291,15 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
288291
let (span, original_path, kind): (Span, &Place<'tcx>, &IllegalMoveOriginKind<'_>) =
289292
match error {
290293
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, .. } => {
293295
(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)
294303
},
295304
};
296305
debug!("report: original_path={:?} span={:?}, kind={:?} \
@@ -548,7 +557,8 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
548557
self.add_move_error_details(err, &binds_to);
549558
}
550559
// 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();
552562
let place_ty = original_path.ty(self.mir, self.infcx.tcx).ty;
553563
let place_desc = match self.describe_place(original_path) {
554564
Some(desc) => format!("`{}`", desc),
@@ -560,6 +570,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
560570
place_ty,
561571
Some(span),
562572
);
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+
);
563579
},
564580
}
565581
}

0 commit comments

Comments
 (0)