]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/mut-borrow-of-mut-ref.rs
Rollup merge of #106321 - compiler-errors:delayed-bug-backtrace, r=Nilstrieb
[rust.git] / tests / ui / borrowck / mut-borrow-of-mut-ref.rs
1 // Suggest not mutably borrowing a mutable reference
2 #![crate_type = "rlib"]
3
4 pub fn f(b: &mut i32) {
5     //~^ ERROR cannot borrow
6     //~| NOTE not mutable
7     //~| NOTE the binding is already a mutable borrow
8     h(&mut b);
9     //~^ NOTE cannot borrow as mutable
10     //~| HELP try removing `&mut` here
11     g(&mut &mut b);
12     //~^ NOTE cannot borrow as mutable
13     //~| HELP try removing `&mut` here
14 }
15
16 pub fn g(b: &mut i32) { //~ NOTE the binding is already a mutable borrow
17     h(&mut &mut b);
18     //~^ ERROR cannot borrow
19     //~| NOTE cannot borrow as mutable
20     //~| HELP try removing `&mut` here
21 }
22
23 pub fn h(_: &mut i32) {}
24
25 trait Foo {
26     fn bar(&mut self);
27 }
28
29 impl Foo for &mut String {
30     fn bar(&mut self) {}
31 }
32
33 pub fn baz(f: &mut String) { //~ HELP consider making the binding mutable
34     f.bar(); //~ ERROR cannot borrow `f` as mutable, as it is not declared as mutable
35     //~^ NOTE cannot borrow as mutable
36 }