1
+ //@ revisions: stable feature
2
+ //@[feature] run-pass
3
+ // gate-test-structural-init
4
+ #![ cfg_attr( feature, feature( structural_init) ) ]
5
+
1
6
// This test enumerates various cases of interest for partial
2
7
// [re]initialization of ADTs and tuples.
3
8
//
4
- // See rust-lang/rust#21232, rust-lang/rust#54986, and rust-lang/rust#54987.
5
- //
6
- // All of tests in this file are expected to change from being
7
- // rejected, at least under NLL (by rust-lang/rust#54986) to being
8
- // **accepted** when rust-lang/rust#54987 is implemented.
9
- // (That's why there are assertions in the code.)
9
+ // All of the tests in this file should fail to compile normally
10
+ // and compile with `feature(structural_init)`.
10
11
//
11
- // See issue-21232-partial-init-and-erroneous-use .rs for cases of
12
- // tests that are meant to continue failing to compile once
13
- // rust-lang/rust#54987 is implemented .
12
+ // See structural_init_invalid .rs for cases of
13
+ // tests that are meant to continue failing to compile
14
+ // with `feature(structural_init)` .
14
15
15
16
struct S < Y > {
16
17
x : u32 ,
@@ -37,11 +38,13 @@ fn borrow_t(t: &T) { assert_eq!(t.0, 10); assert_eq!(*t.1, 20); }
37
38
fn move_t ( t : T ) { assert_eq ! ( t. 0 , 10 ) ; assert_eq ! ( * t. 1 , 20 ) ; }
38
39
39
40
struct Q < F > {
41
+ #[ allow( dead_code) ]
40
42
v : u32 ,
41
43
r : R < F > ,
42
44
}
43
45
44
46
struct R < F > {
47
+ #[ allow( dead_code) ]
45
48
w : u32 ,
46
49
f : F ,
47
50
}
@@ -94,65 +97,65 @@ macro_rules! use_part {
94
97
95
98
fn test_0000_local_fully_init_and_use_struct ( ) {
96
99
let s: S < B > ;
97
- s. x = 10 ; s. y = Box :: new ( 20 ) ; //~ ERROR E0381
100
+ s. x = 10 ; s. y = Box :: new ( 20 ) ; //[stable] ~ ERROR E0381
98
101
use_fully ! ( struct s) ;
99
102
}
100
103
101
104
fn test_0001_local_fully_init_and_use_tuple ( ) {
102
105
let t: T ;
103
- t. 0 = 10 ; t. 1 = Box :: new ( 20 ) ; //~ ERROR E0381
106
+ t. 0 = 10 ; t. 1 = Box :: new ( 20 ) ; //[stable] ~ ERROR E0381
104
107
use_fully ! ( tuple t) ;
105
108
}
106
109
107
110
fn test_0010_local_fully_reinit_and_use_struct ( ) {
108
111
let mut s: S < B > = S :: new ( ) ; drop ( s) ;
109
112
s. x = 10 ; s. y = Box :: new ( 20 ) ;
110
- //~^ ERROR assign to part of moved value: `s` [E0382]
113
+ //[stable] ~^ ERROR assign to part of moved value: `s` [E0382]
111
114
use_fully ! ( struct s) ;
112
115
}
113
116
114
117
fn test_0011_local_fully_reinit_and_use_tuple ( ) {
115
118
let mut t: T = ( 0 , Box :: new ( 0 ) ) ; drop ( t) ;
116
119
t. 0 = 10 ; t. 1 = Box :: new ( 20 ) ;
117
- //~^ ERROR assign to part of moved value: `t` [E0382]
120
+ //[stable] ~^ ERROR assign to part of moved value: `t` [E0382]
118
121
use_fully ! ( tuple t) ;
119
122
}
120
123
121
124
fn test_0100_local_partial_init_and_use_struct ( ) {
122
125
let s: S < B > ;
123
- s. x = 10 ; //~ ERROR E0381
126
+ s. x = 10 ; //[stable] ~ ERROR E0381
124
127
use_part ! ( struct s) ;
125
128
}
126
129
127
130
fn test_0101_local_partial_init_and_use_tuple ( ) {
128
131
let t: T ;
129
- t. 0 = 10 ; //~ ERROR E0381
132
+ t. 0 = 10 ; //[stable] ~ ERROR E0381
130
133
use_part ! ( tuple t) ;
131
134
}
132
135
133
136
fn test_0110_local_partial_reinit_and_use_struct ( ) {
134
137
let mut s: S < B > = S :: new ( ) ; drop ( s) ;
135
138
s. x = 10 ;
136
- //~^ ERROR assign to part of moved value: `s` [E0382]
139
+ //[stable] ~^ ERROR assign to part of moved value: `s` [E0382]
137
140
use_part ! ( struct s) ;
138
141
}
139
142
140
143
fn test_0111_local_partial_reinit_and_use_tuple ( ) {
141
144
let mut t: T = ( 0 , Box :: new ( 0 ) ) ; drop ( t) ;
142
145
t. 0 = 10 ;
143
- //~^ ERROR assign to part of moved value: `t` [E0382]
146
+ //[stable] ~^ ERROR assign to part of moved value: `t` [E0382]
144
147
use_part ! ( tuple t) ;
145
148
}
146
149
147
150
fn test_0200_local_void_init_and_use_struct ( ) {
148
151
let s: S < Void > ;
149
- s. x = 10 ; //~ ERROR E0381
152
+ s. x = 10 ; //[stable] ~ ERROR E0381
150
153
use_part ! ( struct s) ;
151
154
}
152
155
153
156
fn test_0201_local_void_init_and_use_tuple ( ) {
154
157
let t: Tvoid ;
155
- t. 0 = 10 ; //~ ERROR E0381
158
+ t. 0 = 10 ; //[stable] ~ ERROR E0381
156
159
use_part ! ( tuple t) ;
157
160
}
158
161
@@ -167,65 +170,65 @@ fn test_0201_local_void_init_and_use_tuple() {
167
170
168
171
fn test_1000_field_fully_init_and_use_struct ( ) {
169
172
let q: Q < S < B > > ;
170
- q. r . f . x = 10 ; q. r . f . y = Box :: new ( 20 ) ; //~ ERROR E0381
173
+ q. r . f . x = 10 ; q. r . f . y = Box :: new ( 20 ) ; //[stable] ~ ERROR E0381
171
174
use_fully ! ( struct q. r. f) ;
172
175
}
173
176
174
177
fn test_1001_field_fully_init_and_use_tuple ( ) {
175
178
let q: Q < T > ;
176
- q. r . f . 0 = 10 ; q. r . f . 1 = Box :: new ( 20 ) ; //~ ERROR E0381
179
+ q. r . f . 0 = 10 ; q. r . f . 1 = Box :: new ( 20 ) ; //[stable] ~ ERROR E0381
177
180
use_fully ! ( tuple q. r. f) ;
178
181
}
179
182
180
183
fn test_1010_field_fully_reinit_and_use_struct ( ) {
181
184
let mut q: Q < S < B > > = Q :: new ( S :: new ( ) ) ; drop ( q. r ) ;
182
185
q. r . f . x = 10 ; q. r . f . y = Box :: new ( 20 ) ;
183
- //~^ ERROR assign to part of moved value: `q.r` [E0382]
186
+ //[stable] ~^ ERROR assign to part of moved value: `q.r` [E0382]
184
187
use_fully ! ( struct q. r. f) ;
185
188
}
186
189
187
190
fn test_1011_field_fully_reinit_and_use_tuple ( ) {
188
191
let mut q: Q < T > = Q :: new ( ( 0 , Box :: new ( 0 ) ) ) ; drop ( q. r ) ;
189
192
q. r . f . 0 = 10 ; q. r . f . 1 = Box :: new ( 20 ) ;
190
- //~^ ERROR assign to part of moved value: `q.r` [E0382]
193
+ //[stable] ~^ ERROR assign to part of moved value: `q.r` [E0382]
191
194
use_fully ! ( tuple q. r. f) ;
192
195
}
193
196
194
197
fn test_1100_field_partial_init_and_use_struct ( ) {
195
198
let q: Q < S < B > > ;
196
- q. r . f . x = 10 ; //~ ERROR E0381
199
+ q. r . f . x = 10 ; //[stable] ~ ERROR E0381
197
200
use_part ! ( struct q. r. f) ;
198
201
}
199
202
200
203
fn test_1101_field_partial_init_and_use_tuple ( ) {
201
204
let q: Q < T > ;
202
- q. r . f . 0 = 10 ; //~ ERROR E0381
205
+ q. r . f . 0 = 10 ; //[stable] ~ ERROR E0381
203
206
use_part ! ( tuple q. r. f) ;
204
207
}
205
208
206
209
fn test_1110_field_partial_reinit_and_use_struct ( ) {
207
210
let mut q: Q < S < B > > = Q :: new ( S :: new ( ) ) ; drop ( q. r ) ;
208
211
q. r . f . x = 10 ;
209
- //~^ ERROR assign to part of moved value: `q.r` [E0382]
212
+ //[stable] ~^ ERROR assign to part of moved value: `q.r` [E0382]
210
213
use_part ! ( struct q. r. f) ;
211
214
}
212
215
213
216
fn test_1111_field_partial_reinit_and_use_tuple ( ) {
214
217
let mut q: Q < T > = Q :: new ( ( 0 , Box :: new ( 0 ) ) ) ; drop ( q. r ) ;
215
218
q. r . f . 0 = 10 ;
216
- //~^ ERROR assign to part of moved value: `q.r` [E0382]
219
+ //[stable] ~^ ERROR assign to part of moved value: `q.r` [E0382]
217
220
use_part ! ( tuple q. r. f) ;
218
221
}
219
222
220
223
fn test_1200_field_void_init_and_use_struct ( ) {
221
- let mut q: Q < S < Void > > ;
222
- q. r . f . x = 10 ; //~ ERROR E0381
224
+ let q: Q < S < Void > > ;
225
+ q. r . f . x = 10 ; //[stable] ~ ERROR E0381
223
226
use_part ! ( struct q. r. f) ;
224
227
}
225
228
226
229
fn test_1201_field_void_init_and_use_tuple ( ) {
227
- let mut q: Q < Tvoid > ;
228
- q. r . f . 0 = 10 ; //~ ERROR E0381
230
+ let q: Q < Tvoid > ;
231
+ q. r . f . 0 = 10 ; //[stable] ~ ERROR E0381
229
232
use_part ! ( tuple q. r. f) ;
230
233
}
231
234
@@ -242,7 +245,7 @@ fn issue_26996() {
242
245
let mut c = ( 1 , "" . to_owned ( ) ) ;
243
246
match c {
244
247
c2 => {
245
- c. 0 = 2 ; //~ ERROR assign to part of moved value
248
+ c. 0 = 2 ; //[stable] ~ ERROR assign to part of moved value
246
249
assert_eq ! ( c2. 0 , 1 ) ;
247
250
}
248
251
}
@@ -252,15 +255,15 @@ fn issue_27021() {
252
255
let mut c = ( 1 , ( 1 , "" . to_owned ( ) ) ) ;
253
256
match c {
254
257
c2 => {
255
- ( c. 1 ) . 0 = 2 ; //~ ERROR assign to part of moved value
258
+ ( c. 1 ) . 0 = 2 ; //[stable] ~ ERROR assign to part of moved value
256
259
assert_eq ! ( ( c2. 1 ) . 0 , 1 ) ;
257
260
}
258
261
}
259
262
260
263
let mut c = ( 1 , ( 1 , ( 1 , "" . to_owned ( ) ) ) ) ;
261
264
match c. 1 {
262
265
c2 => {
263
- ( ( c. 1 ) . 1 ) . 0 = 3 ; //~ ERROR assign to part of moved value
266
+ ( ( c. 1 ) . 1 ) . 0 = 3 ; //[stable] ~ ERROR assign to part of moved value
264
267
assert_eq ! ( ( c2. 1 ) . 0 , 1 ) ;
265
268
}
266
269
}
0 commit comments