-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #101285 - TaKO8Ki:do-not-suggest-adding-move-when-clo…
…sure-is-already-marked-as-move, r=oli-obk Do not suggest adding `move` to closure when `move` is already used Fixes #101227
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 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
8 changes: 8 additions & 0 deletions
8
src/test/ui/borrowck/do-not-suggest-adding-move-when-closure-is-already-marked-as-move.rs
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,8 @@ | ||
fn main() { | ||
let mut vec: Vec<i32> = Vec::new(); | ||
let closure = move || { | ||
vec.clear(); | ||
let mut iter = vec.iter(); | ||
move || { iter.next() } //~ ERROR captured variable cannot escape `FnMut` closure bod | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
...test/ui/borrowck/do-not-suggest-adding-move-when-closure-is-already-marked-as-move.stderr
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: captured variable cannot escape `FnMut` closure body | ||
--> $DIR/do-not-suggest-adding-move-when-closure-is-already-marked-as-move.rs:6:9 | ||
| | ||
LL | let mut vec: Vec<i32> = Vec::new(); | ||
| ------- variable defined here | ||
LL | let closure = move || { | ||
| - inferred to be a `FnMut` closure | ||
LL | vec.clear(); | ||
| --- variable captured here | ||
LL | let mut iter = vec.iter(); | ||
LL | move || { iter.next() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ returns a closure that contains a reference to a captured variable, which then escapes the closure body | ||
| | ||
= note: `FnMut` closures only have access to their captured variables while they are executing... | ||
= note: ...therefore, they cannot allow references to captured variables to escape | ||
|
||
error: aborting due to previous error | ||
|