Skip to content

Commit a7db0d5

Browse files
nikomatsakiseddyb
authored andcommitted
compile-fail: Beef up borrowck test to include some scenarios where we borrow mutably twice in a row
1 parent 27c6244 commit a7db0d5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/test/compile-fail/borrowck-borrow-overloaded-auto-deref-mut.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ fn deref_extend_mut_field2<'a>(x: &'a mut Own<Point>) -> &'a mut int {
7777
&mut x.y
7878
}
7979

80+
fn deref_extend_mut_field3<'a>(x: &'a mut Own<Point>) {
81+
// Hmm, this is unfortunate, because with ~ it would work,
82+
// but it's presently the expected outcome. See `deref_extend_mut_field4`
83+
// for the workaround.
84+
85+
let _x = &mut x.x;
86+
let _y = &mut x.y; //~ ERROR cannot borrow
87+
}
88+
89+
fn deref_extend_mut_field4<'a>(x: &'a mut Own<Point>) {
90+
let p = &mut **x;
91+
let _x = &mut p.x;
92+
let _y = &mut p.y;
93+
}
94+
8095
fn assign_field1<'a>(x: Own<Point>) {
8196
x.y = 3; //~ ERROR cannot borrow
8297
}
@@ -89,6 +104,11 @@ fn assign_field3<'a>(x: &'a mut Own<Point>) {
89104
x.y = 3;
90105
}
91106

107+
fn assign_field4<'a>(x: &'a mut Own<Point>) {
108+
let _p: &mut Point = &mut **x;
109+
x.y = 3; //~ ERROR cannot borrow
110+
}
111+
92112
// FIXME(eddyb) #12825 This shouldn't attempt to call deref_mut.
93113
/*
94114
fn deref_imm_method(x: Own<Point>) {
@@ -128,4 +148,4 @@ fn assign_method3<'a>(x: &'a mut Own<Point>) {
128148
*x.y_mut() = 3;
129149
}
130150

131-
pub fn main() {}
151+
pub fn main() {}

0 commit comments

Comments
 (0)