]> git.proxmox.com Git - rustc.git/blob - tests/ui/borrowck/borrowck-borrow-overloaded-deref.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / borrowck / borrowck-borrow-overloaded-deref.rs
1 // Test how overloaded deref interacts with borrows when only
2 // Deref and not DerefMut is implemented.
3
4 use std::ops::Deref;
5 use std::rc::Rc;
6
7 fn deref_imm(x: Rc<isize>) {
8 let __isize = &*x;
9 }
10
11 fn deref_mut1(x: Rc<isize>) {
12 let __isize = &mut *x; //~ ERROR cannot borrow
13 }
14
15 fn deref_mut2(mut x: Rc<isize>) {
16 let __isize = &mut *x; //~ ERROR cannot borrow
17 }
18
19 fn deref_extend<'a>(x: &'a Rc<isize>) -> &'a isize {
20 &**x
21 }
22
23 fn deref_extend_mut1<'a>(x: &'a Rc<isize>) -> &'a mut isize {
24 &mut **x //~ ERROR cannot borrow
25 }
26
27 fn deref_extend_mut2<'a>(x: &'a mut Rc<isize>) -> &'a mut isize {
28 &mut **x //~ ERROR cannot borrow
29 }
30
31 fn assign1<'a>(x: Rc<isize>) {
32 *x = 3; //~ ERROR cannot assign
33 }
34
35 fn assign2<'a>(x: &'a Rc<isize>) {
36 **x = 3; //~ ERROR cannot assign
37 }
38
39 fn assign3<'a>(x: &'a mut Rc<isize>) {
40 **x = 3; //~ ERROR cannot assign
41 }
42
43 pub fn main() {}