diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-06-23 03:16:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-23 03:16:26 +0200 |
| commit | b3d99cb63f3125a7b7a5c7cdaa99b7561517d11b (patch) | |
| tree | fb2f3925ed6bc4f04acd83dcef22c85f2592180d | |
| parent | 490d820a25a37369f67a44fecf3805560835c527 (diff) | |
| parent | 953104e60cac57929846a3c3b776f12135c4b398 (diff) | |
| download | rust-b3d99cb63f3125a7b7a5c7cdaa99b7561517d11b.tar.gz rust-b3d99cb63f3125a7b7a5c7cdaa99b7561517d11b.zip | |
Rollup merge of #73600 - Aaron1011:fix/move-in-macro, r=ecstatic-morse
Fix spurious 'value moved here in previous iteration of loop' messages Fixes #46099 Previously, we would check the 'move' and 'use' spans to see if we should emit this message. However, this can give false positives when macros are involved, since two distinct expressions may end up with the same span. Instead, we check the actual MIR `Location`, which eliminates false positives.
| -rw-r--r-- | src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/moves/issue-46099-move-in-macro.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/moves/issue-46099-move-in-macro.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/moves/move-in-guard-2.stderr | 5 |
4 files changed, 34 insertions, 2 deletions
diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index eb07c7e65f5..8d7944004c7 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -138,7 +138,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), diff --git a/src/test/ui/moves/issue-46099-move-in-macro.rs b/src/test/ui/moves/issue-46099-move-in-macro.rs new file mode 100644 index 00000000000..576fe1f4c89 --- /dev/null +++ b/src/test/ui/moves/issue-46099-move-in-macro.rs @@ -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 +} diff --git a/src/test/ui/moves/issue-46099-move-in-macro.stderr b/src/test/ui/moves/issue-46099-move-in-macro.stderr new file mode 100644 index 00000000000..83c99db8709 --- /dev/null +++ b/src/test/ui/moves/issue-46099-move-in-macro.stderr @@ -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 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/moves/move-in-guard-2.stderr b/src/test/ui/moves/move-in-guard-2.stderr index 8bd405279c5..00d89f55071 100644 --- a/src/test/ui/moves/move-in-guard-2.stderr +++ b/src/test/ui/moves/move-in-guard-2.stderr @@ -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 |
