]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/mut-borrow-of-mut-ref.rs
Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser
[rust.git] / src / test / 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     //~^ NOTE the binding is already a mutable borrow
6     //~| NOTE the binding is already a mutable borrow
7     h(&mut b);
8     //~^ ERROR cannot borrow
9     //~| NOTE cannot borrow as mutable
10     //~| HELP try removing `&mut` here
11     g(&mut &mut b);
12     //~^ ERROR cannot borrow
13     //~| NOTE cannot borrow as mutable
14     //~| HELP try removing `&mut` here
15 }
16
17 pub fn g(b: &mut i32) { //~ NOTE the binding is already a mutable borrow
18     h(&mut &mut b);
19     //~^ ERROR cannot borrow
20     //~| NOTE cannot borrow as mutable
21     //~| HELP try removing `&mut` here
22 }
23
24 pub fn h(_: &mut i32) {}
25
26 trait Foo {
27     fn bar(&mut self);
28 }
29
30 impl Foo for &mut String {
31     fn bar(&mut self) {}
32 }
33
34 pub fn baz(f: &mut String) { //~ HELP consider making the binding mutable
35     f.bar(); //~ ERROR cannot borrow `f` as mutable, as it is not declared as mutable
36     //~^ NOTE cannot borrow as mutable
37 }