]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-argument.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-argument.rs
1 #[derive(Copy, Clone)]
2 struct S;
3
4 impl S {
5     fn mutate(&mut self) {
6     }
7 }
8
9 fn func(arg: S) {
10     arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
11 }
12
13 impl S {
14     fn method(&self, arg: S) {
15         arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
16     }
17 }
18
19 trait T {
20     fn default(&self, arg: S) {
21         arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
22     }
23 }
24
25 impl T for S {}
26
27 fn main() {
28     let s = S;
29     func(s);
30     s.method(s);
31     s.default(s);
32     (|arg: S| { arg.mutate() })(s);
33     //~^ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
34 }