Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters