2014-03-04 16:26:51 -06:00
|
|
|
// Test how overloaded deref interacts with borrows when only
|
|
|
|
// Deref and not DerefMut is implemented.
|
|
|
|
|
|
|
|
use std::ops::Deref;
|
2019-07-07 08:16:58 -05:00
|
|
|
use std::rc::Rc;
|
2014-03-04 16:26:51 -06:00
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_imm(x: Rc<isize>) {
|
2015-02-18 04:42:01 -06:00
|
|
|
let __isize = &*x;
|
2014-03-04 16:26:51 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_mut1(x: Rc<isize>) {
|
2015-02-18 04:42:01 -06:00
|
|
|
let __isize = &mut *x; //~ ERROR cannot borrow
|
2014-03-04 16:26:51 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_mut2(mut x: Rc<isize>) {
|
2015-02-18 04:42:01 -06:00
|
|
|
let __isize = &mut *x; //~ ERROR cannot borrow
|
2014-03-04 16:26:51 -06:00
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_extend<'a>(x: &'a Rc<isize>) -> &'a isize {
|
2014-03-04 16:26:51 -06:00
|
|
|
&**x
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_extend_mut1<'a>(x: &'a Rc<isize>) -> &'a mut isize {
|
2014-03-04 16:26:51 -06:00
|
|
|
&mut **x //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn deref_extend_mut2<'a>(x: &'a mut Rc<isize>) -> &'a mut isize {
|
2014-03-04 16:26:51 -06:00
|
|
|
&mut **x //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn assign1<'a>(x: Rc<isize>) {
|
2014-03-04 16:26:51 -06:00
|
|
|
*x = 3; //~ ERROR cannot assign
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn assign2<'a>(x: &'a Rc<isize>) {
|
2014-03-04 16:26:51 -06:00
|
|
|
**x = 3; //~ ERROR cannot assign
|
|
|
|
}
|
|
|
|
|
2015-01-08 04:54:35 -06:00
|
|
|
fn assign3<'a>(x: &'a mut Rc<isize>) {
|
2014-03-04 16:26:51 -06:00
|
|
|
**x = 3; //~ ERROR cannot assign
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {}
|