2018-05-25 13:33:15 -05:00
|
|
|
// Suggest not mutably borrowing a mutable reference
|
2020-10-08 09:21:12 -05:00
|
|
|
#![crate_type = "rlib"]
|
2018-05-25 13:33:15 -05:00
|
|
|
|
2020-10-08 09:21:12 -05:00
|
|
|
pub fn f(b: &mut i32) {
|
2022-12-30 00:46:17 -06:00
|
|
|
//~^ ERROR cannot borrow
|
|
|
|
//~| NOTE not mutable
|
2021-03-17 20:45:49 -05:00
|
|
|
//~| NOTE the binding is already a mutable borrow
|
|
|
|
h(&mut b);
|
2022-12-30 00:46:17 -06:00
|
|
|
//~^ NOTE cannot borrow as mutable
|
2021-07-25 09:23:48 -05:00
|
|
|
//~| HELP try removing `&mut` here
|
2020-10-08 09:21:12 -05:00
|
|
|
g(&mut &mut b);
|
2022-12-30 00:46:17 -06:00
|
|
|
//~^ NOTE cannot borrow as mutable
|
2021-07-25 09:23:48 -05:00
|
|
|
//~| HELP try removing `&mut` here
|
2018-05-25 13:33:15 -05:00
|
|
|
}
|
|
|
|
|
2021-03-17 20:45:49 -05:00
|
|
|
pub fn g(b: &mut i32) { //~ NOTE the binding is already a mutable borrow
|
|
|
|
h(&mut &mut b);
|
|
|
|
//~^ ERROR cannot borrow
|
|
|
|
//~| NOTE cannot borrow as mutable
|
|
|
|
//~| HELP try removing `&mut` here
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn h(_: &mut i32) {}
|
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
fn bar(&mut self);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Foo for &mut String {
|
|
|
|
fn bar(&mut self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn baz(f: &mut String) { //~ HELP consider making the binding mutable
|
|
|
|
f.bar(); //~ ERROR cannot borrow `f` as mutable, as it is not declared as mutable
|
|
|
|
//~^ NOTE cannot borrow as mutable
|
|
|
|
}
|