blob: 83eab7fdeab6a3529078fd75f6fff432f04995d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Test how overloaded deref interacts with borrows when only
// Deref and not DerefMut is implemented.
use std::ops::Deref;
use std::rc::Rc;
struct Point {
x: isize,
y: isize
}
impl Point {
fn get(&self) -> (isize, isize) {
(self.x, self.y)
}
fn set(&mut self, x: isize, y: isize) {
self.x = x;
self.y = y;
}
fn x_ref(&self) -> &isize {
&self.x
}
fn y_mut(&mut self) -> &mut isize {
&mut self.y
}
}
fn deref_imm_field(x: Rc<Point>) {
let __isize = &x.y;
}
fn deref_mut_field1(x: Rc<Point>) {
let __isize = &mut x.y; //~ ERROR cannot borrow
}
fn deref_mut_field2(mut x: Rc<Point>) {
let __isize = &mut x.y; //~ ERROR cannot borrow
}
fn deref_extend_field(x: &Rc<Point>) -> &isize {
&x.y
}
fn deref_extend_mut_field1(x: &Rc<Point>) -> &mut isize {
&mut x.y //~ ERROR cannot borrow
}
fn deref_extend_mut_field2(x: &mut Rc<Point>) -> &mut isize {
&mut x.y //~ ERROR cannot borrow
}
fn assign_field1<'a>(x: Rc<Point>) {
x.y = 3; //~ ERROR cannot assign
}
fn assign_field2<'a>(x: &'a Rc<Point>) {
x.y = 3; //~ ERROR cannot assign
}
fn assign_field3<'a>(x: &'a mut Rc<Point>) {
x.y = 3; //~ ERROR cannot assign
}
fn deref_imm_method(x: Rc<Point>) {
let __isize = x.get();
}
fn deref_mut_method1(x: Rc<Point>) {
x.set(0, 0); //~ ERROR cannot borrow
}
fn deref_mut_method2(mut x: Rc<Point>) {
x.set(0, 0); //~ ERROR cannot borrow
}
fn deref_extend_method(x: &Rc<Point>) -> &isize {
x.x_ref()
}
fn deref_extend_mut_method1(x: &Rc<Point>) -> &mut isize {
x.y_mut() //~ ERROR cannot borrow
}
fn deref_extend_mut_method2(x: &mut Rc<Point>) -> &mut isize {
x.y_mut() //~ ERROR cannot borrow
}
fn assign_method1<'a>(x: Rc<Point>) {
*x.y_mut() = 3; //~ ERROR cannot borrow
}
fn assign_method2<'a>(x: &'a Rc<Point>) {
*x.y_mut() = 3; //~ ERROR cannot borrow
}
fn assign_method3<'a>(x: &'a mut Rc<Point>) {
*x.y_mut() = 3; //~ ERROR cannot borrow
}
pub fn main() {}
|