-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #64642 - cuviper:move-for-loop-snippet, r=varkor
Fix the span used to suggest avoiding for-loop moves It was using the snippet from the "use" span, which often renders the same, but with closures that snippet is on the start of the closure where the value is captured. We should be using the snippet from the span where it was moved into the `for` loop, which is `move_span`. Fixes #64559.
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
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,6 @@ | ||
fn main() { | ||
let orig = vec![true]; | ||
for _val in orig {} | ||
let _closure = || orig; | ||
//~^ ERROR use of moved value: `orig` | ||
} |
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,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`. |