blob: 8bf2625de6da6b8678c7f9a2b1666702f3eb8980 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// 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() {}
|