-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use structured suggestion for #113174
When encountering a for loop that is rejected by the borrow checker because it is being advanced within its body, provide a structured suggestion for `while let Some(pat) = iter.next()`.
- Loading branch information
Showing
4 changed files
with
265 additions
and
32 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,41 @@ | ||
// run-rustfix | ||
|
||
fn test1() { | ||
let mut chars = "Hello".chars(); | ||
let iter = chars.by_ref(); | ||
while let Some(_c) = iter.next() { | ||
iter.next(); //~ ERROR cannot borrow `chars` as mutable more than once at a time | ||
} | ||
} | ||
|
||
fn test2() { | ||
let v = vec![1, 2, 3]; | ||
let mut iter = v.iter(); | ||
while let Some(_i) = iter.next() { | ||
iter.next(); //~ ERROR borrow of moved value: `iter` | ||
} | ||
} | ||
|
||
fn test3() { | ||
let v = vec![(), (), ()]; | ||
let mut i = v.iter(); | ||
let iter = i.by_ref(); | ||
while let Some(()) = iter.next() { | ||
iter.next(); //~ ERROR cannot borrow `i` | ||
} | ||
} | ||
|
||
fn test4() { | ||
let v = vec![(), (), ()]; | ||
let mut iter = v.iter(); | ||
while let Some(()) = iter.next() { | ||
iter.next(); //~ ERROR borrow of moved value: `iter` | ||
} | ||
} | ||
|
||
fn main() { | ||
test1(); | ||
test2(); | ||
test3(); | ||
test4(); | ||
} |
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