2018-05-25 18:33:15 +00:00
|
|
|
// Suggest not mutably borrowing a mutable reference
|
2020-10-08 14:21:12 +00:00
|
|
|
#![crate_type = "rlib"]
|
2018-05-25 18:33:15 +00:00
|
|
|
|
2020-10-08 14:21:12 +00:00
|
|
|
pub fn f(b: &mut i32) {
|
2022-12-30 06:46:17 +00:00
|
|
|
//~^ ERROR cannot borrow
|
|
|
|
//~| NOTE not mutable
|
2021-03-18 01:45:49 +00:00
|
|
|
//~| NOTE the binding is already a mutable borrow
|
|
|
|
h(&mut b);
|
2022-12-30 06:46:17 +00:00
|
|
|
//~^ NOTE cannot borrow as mutable
|
2021-07-25 14:23:48 +00:00
|
|
|
//~| HELP try removing `&mut` here
|
2020-10-08 14:21:12 +00:00
|
|
|
g(&mut &mut b);
|
2022-12-30 06:46:17 +00:00
|
|
|
//~^ NOTE cannot borrow as mutable
|
2021-07-25 14:23:48 +00:00
|
|
|
//~| HELP try removing `&mut` here
|
2018-05-25 18:33:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 01:45:49 +00: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
|
|
|
|
}
|