Skip to content

Commit f328f70

Browse files
committed
structural init tests
with incorrect error output though
1 parent de936c7 commit f328f70

File tree

5 files changed

+93
-88
lines changed

5 files changed

+93
-88
lines changed

tests/ui/borrowck/structural_init.rs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
//@ revisions: stable feature
2+
//@[feature] run-pass
3+
// gate-test-structural-init
4+
#![cfg_attr(feature, feature(structural_init))]
5+
16
// This test enumerates various cases of interest for partial
27
// [re]initialization of ADTs and tuples.
38
//
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)`.
1011
//
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)`.
1415

1516
struct S<Y> {
1617
x: u32,
@@ -37,11 +38,13 @@ fn borrow_t(t: &T) { assert_eq!(t.0, 10); assert_eq!(*t.1, 20); }
3738
fn move_t(t: T) { assert_eq!(t.0, 10); assert_eq!(*t.1, 20); }
3839

3940
struct Q<F> {
41+
#[allow(dead_code)]
4042
v: u32,
4143
r: R<F>,
4244
}
4345

4446
struct R<F> {
47+
#[allow(dead_code)]
4548
w: u32,
4649
f: F,
4750
}
@@ -94,65 +97,65 @@ macro_rules! use_part {
9497

9598
fn test_0000_local_fully_init_and_use_struct() {
9699
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
98101
use_fully!(struct s);
99102
}
100103

101104
fn test_0001_local_fully_init_and_use_tuple() {
102105
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
104107
use_fully!(tuple t);
105108
}
106109

107110
fn test_0010_local_fully_reinit_and_use_struct() {
108111
let mut s: S<B> = S::new(); drop(s);
109112
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]
111114
use_fully!(struct s);
112115
}
113116

114117
fn test_0011_local_fully_reinit_and_use_tuple() {
115118
let mut t: T = (0, Box::new(0)); drop(t);
116119
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]
118121
use_fully!(tuple t);
119122
}
120123

121124
fn test_0100_local_partial_init_and_use_struct() {
122125
let s: S<B>;
123-
s.x = 10; //~ ERROR E0381
126+
s.x = 10; //[stable]~ ERROR E0381
124127
use_part!(struct s);
125128
}
126129

127130
fn test_0101_local_partial_init_and_use_tuple() {
128131
let t: T;
129-
t.0 = 10; //~ ERROR E0381
132+
t.0 = 10; //[stable]~ ERROR E0381
130133
use_part!(tuple t);
131134
}
132135

133136
fn test_0110_local_partial_reinit_and_use_struct() {
134137
let mut s: S<B> = S::new(); drop(s);
135138
s.x = 10;
136-
//~^ ERROR assign to part of moved value: `s` [E0382]
139+
//[stable]~^ ERROR assign to part of moved value: `s` [E0382]
137140
use_part!(struct s);
138141
}
139142

140143
fn test_0111_local_partial_reinit_and_use_tuple() {
141144
let mut t: T = (0, Box::new(0)); drop(t);
142145
t.0 = 10;
143-
//~^ ERROR assign to part of moved value: `t` [E0382]
146+
//[stable]~^ ERROR assign to part of moved value: `t` [E0382]
144147
use_part!(tuple t);
145148
}
146149

147150
fn test_0200_local_void_init_and_use_struct() {
148151
let s: S<Void>;
149-
s.x = 10; //~ ERROR E0381
152+
s.x = 10; //[stable]~ ERROR E0381
150153
use_part!(struct s);
151154
}
152155

153156
fn test_0201_local_void_init_and_use_tuple() {
154157
let t: Tvoid;
155-
t.0 = 10; //~ ERROR E0381
158+
t.0 = 10; //[stable]~ ERROR E0381
156159
use_part!(tuple t);
157160
}
158161

@@ -167,65 +170,65 @@ fn test_0201_local_void_init_and_use_tuple() {
167170

168171
fn test_1000_field_fully_init_and_use_struct() {
169172
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
171174
use_fully!(struct q.r.f);
172175
}
173176

174177
fn test_1001_field_fully_init_and_use_tuple() {
175178
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
177180
use_fully!(tuple q.r.f);
178181
}
179182

180183
fn test_1010_field_fully_reinit_and_use_struct() {
181184
let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r);
182185
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]
184187
use_fully!(struct q.r.f);
185188
}
186189

187190
fn test_1011_field_fully_reinit_and_use_tuple() {
188191
let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r);
189192
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]
191194
use_fully!(tuple q.r.f);
192195
}
193196

194197
fn test_1100_field_partial_init_and_use_struct() {
195198
let q: Q<S<B>>;
196-
q.r.f.x = 10; //~ ERROR E0381
199+
q.r.f.x = 10; //[stable]~ ERROR E0381
197200
use_part!(struct q.r.f);
198201
}
199202

200203
fn test_1101_field_partial_init_and_use_tuple() {
201204
let q: Q<T>;
202-
q.r.f.0 = 10; //~ ERROR E0381
205+
q.r.f.0 = 10; //[stable]~ ERROR E0381
203206
use_part!(tuple q.r.f);
204207
}
205208

206209
fn test_1110_field_partial_reinit_and_use_struct() {
207210
let mut q: Q<S<B>> = Q::new(S::new()); drop(q.r);
208211
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]
210213
use_part!(struct q.r.f);
211214
}
212215

213216
fn test_1111_field_partial_reinit_and_use_tuple() {
214217
let mut q: Q<T> = Q::new((0, Box::new(0))); drop(q.r);
215218
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]
217220
use_part!(tuple q.r.f);
218221
}
219222

220223
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
223226
use_part!(struct q.r.f);
224227
}
225228

226229
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
229232
use_part!(tuple q.r.f);
230233
}
231234

@@ -242,7 +245,7 @@ fn issue_26996() {
242245
let mut c = (1, "".to_owned());
243246
match c {
244247
c2 => {
245-
c.0 = 2; //~ ERROR assign to part of moved value
248+
c.0 = 2; //[stable]~ ERROR assign to part of moved value
246249
assert_eq!(c2.0, 1);
247250
}
248251
}
@@ -252,15 +255,15 @@ fn issue_27021() {
252255
let mut c = (1, (1, "".to_owned()));
253256
match c {
254257
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
256259
assert_eq!((c2.1).0, 1);
257260
}
258261
}
259262

260263
let mut c = (1, (1, (1, "".to_owned())));
261264
match c.1 {
262265
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
264267
assert_eq!((c2.1).0, 1);
265268
}
266269
}

0 commit comments

Comments
 (0)