Rollup merge of #70264 - tirr-c:issue-69789-mut-suggestion, r=estebank
Fix invalid suggestion on `&mut` iterators yielding `&` references Fixes #69789. rustc suggested an invalid code when `&` reference from `&mut` iterator is mutated. The compiler knew we're mutating a value behind `&` reference, but as the assignment RHS is from desugaring, it could only see the iterator expression from source and inserted `mut` there. r? @estebank
This commit is contained in:
commit
ab2817bbd0
3 changed files with 82 additions and 23 deletions
11
src/test/ui/borrowck/issue-69789-iterator-mut-suggestion.rs
Normal file
11
src/test/ui/borrowck/issue-69789-iterator-mut-suggestion.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// Regression test for #69789: rustc generated an invalid suggestion
|
||||
// when `&` reference from `&mut` iterator is mutated.
|
||||
|
||||
fn main() {
|
||||
for item in &mut std::iter::empty::<&'static ()>() {
|
||||
//~^ NOTE this iterator yields `&` references
|
||||
*item = ();
|
||||
//~^ ERROR cannot assign
|
||||
//~| NOTE cannot be written
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
error[E0594]: cannot assign to `*item` which is behind a `&` reference
|
||||
--> $DIR/issue-69789-iterator-mut-suggestion.rs:7:9
|
||||
|
|
||||
LL | for item in &mut std::iter::empty::<&'static ()>() {
|
||||
| -------------------------------------- this iterator yields `&` references
|
||||
LL |
|
||||
LL | *item = ();
|
||||
| ^^^^^^^^^^ `item` is a `&` reference, so the data it refers to cannot be written
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0594`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue