Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_mir/borrow_check/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
}
if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
let sess = self.infcx.tcx.sess;
if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
err.span_suggestion(
move_span,
"consider borrowing to avoid moving into the for loop",
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/issues/issue-64559.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let orig = vec![true];
for _val in orig {}
let _closure = || orig;
//~^ ERROR use of moved value: `orig`
}
18 changes: 18 additions & 0 deletions src/test/ui/issues/issue-64559.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0382]: use of moved value: `orig`
--> $DIR/issue-64559.rs:4:20
|
LL | let orig = vec![true];
| ---- move occurs because `orig` has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
LL | for _val in orig {}
| ----
| |
| value moved here
| help: consider borrowing to avoid moving into the for loop: `&orig`
LL | let _closure = || orig;
| ^^ ---- use occurs due to use in closure
| |
| value used here after move

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.