Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spurious 'value moved here in previous iteration of loop' messages #73600

Merged
merged 1 commit into from
Jun 23, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

let move_msg = if move_spans.for_closure() { " into closure" } else { "" };

if span == move_span {
if location == move_out.source {
err.span_label(
span,
format!("value moved{} here, in previous iteration of loop", move_msg),
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/moves/issue-46099-move-in-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for issue #46099
// Tests that we don't emit spurious
// 'value moved in previous iteration of loop' message

macro_rules! test {
($v:expr) => {{
drop(&$v);
$v
}}
}

fn main() {
let b = Box::new(true);
test!({b}); //~ ERROR use of moved value
}
14 changes: 14 additions & 0 deletions src/test/ui/moves/issue-46099-move-in-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0382]: use of moved value: `b`
--> $DIR/issue-46099-move-in-macro.rs:14:12
|
LL | let b = Box::new(true);
| - move occurs because `b` has type `std::boxed::Box<bool>`, which does not implement the `Copy` trait
LL | test!({b});
| ^
| |
| value moved here
| value used here after move
Comment on lines +6 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this is not formatted as

Suggested change
LL | test!({b});
| ^
| |
| value moved here
| value used here after move
LL | test!({b});
| ^ value moved here
| | value used here after move

It's outside the scope of this PR, just wondering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure - I think that might just be how the diagnostic framework formats messages.


error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.
5 changes: 4 additions & 1 deletion src/test/ui/moves/move-in-guard-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ LL | let x: Box<_> = box 1;
| - move occurs because `x` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
...
LL | (_, 2) if take(x) => (),
| ^ value moved here, in previous iteration of loop
| ^
| |
| value moved here
| value used here after move

error: aborting due to previous error

Expand Down