10
10
11
11
struct A { a : int , b : Box < int > }
12
12
13
- fn borrow < T > ( _: & T ) { }
14
-
15
- fn use_after_move ( ) {
13
+ fn deref_after_move ( ) {
16
14
let x = A { a : 1 , b : box 2 } ;
17
15
drop ( x. b ) ;
18
16
drop ( * x. b ) ; //~ ERROR use of partially moved value: `*x.b`
19
17
}
20
18
21
- fn use_after_fu_move ( ) {
19
+ fn deref_after_fu_move ( ) {
22
20
let x = A { a : 1 , b : box 2 } ;
23
21
let y = A { a : 3 , .. x } ;
24
22
drop ( * x. b ) ; //~ ERROR use of partially moved value: `*x.b`
@@ -27,35 +25,37 @@ fn use_after_fu_move() {
27
25
fn borrow_after_move ( ) {
28
26
let x = A { a : 1 , b : box 2 } ;
29
27
drop ( x. b ) ;
30
- borrow ( & x. b ) ; //~ ERROR use of moved value: `x.b`
28
+ let p = & x. b ; //~ ERROR use of moved value: `x.b`
29
+ drop ( * * p) ;
31
30
}
32
31
33
32
fn borrow_after_fu_move ( ) {
34
33
let x = A { a : 1 , b : box 2 } ;
35
34
let _y = A { a : 3 , .. x } ;
36
- borrow ( & x. b ) ; //~ ERROR use of moved value: `x.b`
35
+ let p = & x. b ; //~ ERROR use of moved value: `x.b`
36
+ drop ( * * p) ;
37
37
}
38
38
39
39
fn move_after_borrow ( ) {
40
40
let x = A { a : 1 , b : box 2 } ;
41
- let y = & x. b ;
41
+ let p = & x. b ;
42
42
drop ( x. b ) ; //~ ERROR cannot move out of `x.b` because it is borrowed
43
- borrow ( & * y ) ;
43
+ drop ( * * p ) ;
44
44
}
45
45
46
46
fn fu_move_after_borrow ( ) {
47
47
let x = A { a : 1 , b : box 2 } ;
48
- let y = & x. b ;
49
- let _z = A { a : 3 , .. x } ; //~ ERROR cannot move out of `x.b` because it is borrowed
50
- borrow ( & * y ) ;
48
+ let p = & x. b ;
49
+ let _y = A { a : 3 , .. x } ; //~ ERROR cannot move out of `x.b` because it is borrowed
50
+ drop ( * * p ) ;
51
51
}
52
52
53
53
fn mut_borrow_after_mut_borrow ( ) {
54
54
let mut x = A { a : 1 , b : box 2 } ;
55
- let y = & mut x. a ;
56
- let z = & mut x. a ; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
57
- drop ( * y ) ;
58
- drop ( * z ) ;
55
+ let p = & mut x. a ;
56
+ let q = & mut x. a ; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
57
+ drop ( * p ) ;
58
+ drop ( * q ) ;
59
59
}
60
60
61
61
fn move_after_move ( ) {
@@ -84,7 +84,21 @@ fn fu_move_after_fu_move() {
84
84
85
85
// The following functions aren't yet accepted, but they should be.
86
86
87
- fn use_after_field_assign_after_uninit ( ) {
87
+ fn move_after_borrow_correct ( ) {
88
+ let x = A { a : 1 , b : box 2 } ;
89
+ let p = & x. a ;
90
+ drop ( x. b ) ; //~ ERROR cannot move out of `x.b` because it is borrowed
91
+ drop ( * p) ;
92
+ }
93
+
94
+ fn fu_move_after_borrow_correct ( ) {
95
+ let x = A { a : 1 , b : box 2 } ;
96
+ let p = & x. a ;
97
+ let _y = A { a : 3 , .. x } ; //~ ERROR cannot move out of `x.b` because it is borrowed
98
+ drop ( * p) ;
99
+ }
100
+
101
+ fn copy_after_field_assign_after_uninit ( ) {
88
102
let mut x: A ;
89
103
x. a = 1 ;
90
104
drop ( x. a ) ; //~ ERROR use of possibly uninitialized variable: `x.a`
@@ -93,7 +107,8 @@ fn use_after_field_assign_after_uninit() {
93
107
fn borrow_after_field_assign_after_uninit ( ) {
94
108
let mut x: A ;
95
109
x. a = 1 ;
96
- borrow ( & x. a ) ; //~ ERROR use of possibly uninitialized variable: `x.a`
110
+ let p = & x. a ; //~ ERROR use of possibly uninitialized variable: `x.a`
111
+ drop ( * p) ;
97
112
}
98
113
99
114
fn move_after_field_assign_after_uninit ( ) {
@@ -103,8 +118,8 @@ fn move_after_field_assign_after_uninit() {
103
118
}
104
119
105
120
fn main ( ) {
106
- use_after_move ( ) ;
107
- use_after_fu_move ( ) ;
121
+ deref_after_move ( ) ;
122
+ deref_after_fu_move ( ) ;
108
123
109
124
borrow_after_move ( ) ;
110
125
borrow_after_fu_move ( ) ;
@@ -117,7 +132,10 @@ fn main() {
117
132
fu_move_after_move ( ) ;
118
133
fu_move_after_fu_move ( ) ;
119
134
120
- use_after_field_assign_after_uninit ( ) ;
135
+ move_after_borrow_correct ( ) ;
136
+ fu_move_after_borrow_correct ( ) ;
137
+
138
+ copy_after_field_assign_after_uninit ( ) ;
121
139
borrow_after_field_assign_after_uninit ( ) ;
122
140
move_after_field_assign_after_uninit ( ) ;
123
141
}
0 commit comments