rust/tests/ui/borrowck/issue-62387-suggest-iter-mut.fixed

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
577 B
Rust
Raw Normal View History

// run-rustfix
#![allow(unused_mut)]
#![allow(dead_code)]
#[derive(Debug)]
struct A {
a: i32,
}
impl A {
fn double(&mut self) {
self.a += self.a
}
}
fn baz() {
let mut v = [A { a: 4 }];
v.iter_mut().for_each(|a| a.double());
//~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference
println!("{:?}", v);
}
fn bar() {
let mut v = [A { a: 4 }];
v.iter_mut().rev().rev().for_each(|a| a.double());
//~^ ERROR cannot borrow `*a` as mutable, as it is behind a `&` reference
println!("{:?}", v);
}
fn main() {}