2017-03-26 11:35:46 -05:00
|
|
|
pub enum X {
|
2017-02-06 17:41:28 -06:00
|
|
|
Y
|
|
|
|
}
|
|
|
|
|
2017-03-26 11:35:46 -05:00
|
|
|
pub struct Z {
|
2017-02-06 17:41:28 -06:00
|
|
|
x: X
|
|
|
|
}
|
|
|
|
|
2017-03-26 17:35:50 -05:00
|
|
|
fn main() {
|
2017-02-06 17:41:28 -06:00
|
|
|
let z = Z { x: X::Y };
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut z.x; //~ ERROR cannot borrow
|
2017-02-06 17:41:28 -06:00
|
|
|
}
|
2017-03-26 11:35:46 -05:00
|
|
|
|
2017-03-26 17:35:50 -05:00
|
|
|
impl Z {
|
|
|
|
fn foo<'z>(&'z self) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut self.x; //~ ERROR cannot borrow
|
2017-03-26 17:35:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo1(&self, other: &Z) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut self.x; //~ ERROR cannot borrow
|
|
|
|
let _ = &mut other.x; //~ ERROR cannot borrow
|
2017-03-26 17:35:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo2<'a>(&'a self, other: &Z) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut self.x; //~ ERROR cannot borrow
|
|
|
|
let _ = &mut other.x; //~ ERROR cannot borrow
|
2017-03-26 17:35:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo3<'a>(self: &'a Self, other: &Z) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut self.x; //~ ERROR cannot borrow
|
|
|
|
let _ = &mut other.x; //~ ERROR cannot borrow
|
2017-03-26 17:35:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo4(other: &Z) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut other.x; //~ ERROR cannot borrow
|
2017-03-26 17:35:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-03-26 11:35:46 -05:00
|
|
|
pub fn with_arg(z: Z, w: &Z) {
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = &mut z.x; //~ ERROR cannot borrow
|
|
|
|
let _ = &mut w.x; //~ ERROR cannot borrow
|
2017-03-26 11:35:46 -05:00
|
|
|
}
|
2017-04-06 05:20:24 -05:00
|
|
|
|
|
|
|
pub fn with_tuple() {
|
|
|
|
let mut y = 0;
|
|
|
|
let x = (&y,);
|
2017-12-31 17:32:41 -06:00
|
|
|
*x.0 = 1;
|
2021-07-02 11:29:49 -05:00
|
|
|
//~^ ERROR cannot assign to `*x.0`, which is behind a `&` reference
|
2017-04-06 05:20:24 -05:00
|
|
|
}
|