Skip to content

Commit 8a1dd69

Browse files
committed
Add test for restriction of anonymous types on validation
1 parent d4ad050 commit 8a1dd69

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![allow(incomplete_features)]
2+
#![feature(unnamed_fields)]
3+
4+
fn f() -> struct { field: u8 } {} //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
5+
//~^ ERROR anonymous structs are unimplemented
6+
7+
fn f2(a: struct { field: u8 } ) {} //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
8+
//~^ ERROR anonymous structs are unimplemented
9+
10+
union G {
11+
field: struct { field: u8 } //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
12+
//~^ ERROR anonymous structs are unimplemented
13+
}
14+
//~| ERROR unions may not contain fields that need dropping [E0740]
15+
16+
struct H { _: u8 } // Should error after hir checks
17+
18+
struct I(struct { field: u8 }, u8); //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
19+
//~^ ERROR anonymous structs are unimplemented
20+
21+
enum J {
22+
K(struct { field: u8 }), //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
23+
//~^ ERROR anonymous structs are unimplemented
24+
L {
25+
_ : struct { field: u8 } //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
26+
//~^ ERROR anonymous fields are not allowed outside of structs or unions
27+
//~| ERROR anonymous structs are unimplemented
28+
},
29+
M {
30+
_ : u8 //~ ERROR anonymous fields are not allowed outside of structs or unions
31+
}
32+
}
33+
34+
static M: union { field: u8 } = 0; //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields
35+
//~^ ERROR anonymous unions are unimplemented
36+
37+
type N = union { field: u8 }; //~ ERROR anonymous unions are not allowed outside of unnamed struct or union fields
38+
//~^ ERROR anonymous unions are unimplemented
39+
40+
fn main() {
41+
const O: struct { field: u8 } = 0; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
42+
//~^ ERROR anonymous structs are unimplemented
43+
44+
let p: [struct { field: u8 }; 1]; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
45+
//~^ ERROR anonymous structs are unimplemented
46+
47+
let q: (struct { field: u8 }, u8); //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
48+
//~^ ERROR anonymous structs are unimplemented
49+
50+
let cl = || -> struct { field: u8 } {}; //~ ERROR anonymous structs are not allowed outside of unnamed struct or union fields
51+
//~^ ERROR anonymous structs are unimplemented
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
error: anonymous structs are not allowed outside of unnamed struct or union fields
2+
--> $DIR/restrict_anonymous.rs:4:11
3+
|
4+
LL | fn f() -> struct { field: u8 } {}
5+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
6+
7+
error: anonymous structs are not allowed outside of unnamed struct or union fields
8+
--> $DIR/restrict_anonymous.rs:7:10
9+
|
10+
LL | fn f2(a: struct { field: u8 } ) {}
11+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
12+
13+
error: anonymous structs are not allowed outside of unnamed struct or union fields
14+
--> $DIR/restrict_anonymous.rs:11:12
15+
|
16+
LL | field: struct { field: u8 }
17+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
18+
19+
error: anonymous structs are not allowed outside of unnamed struct or union fields
20+
--> $DIR/restrict_anonymous.rs:18:10
21+
|
22+
LL | struct I(struct { field: u8 }, u8);
23+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
24+
25+
error: anonymous structs are not allowed outside of unnamed struct or union fields
26+
--> $DIR/restrict_anonymous.rs:22:7
27+
|
28+
LL | K(struct { field: u8 }),
29+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
30+
31+
error: anonymous fields are not allowed outside of structs or unions
32+
--> $DIR/restrict_anonymous.rs:25:9
33+
|
34+
LL | _ : struct { field: u8 }
35+
| -^^^^^^^^^^^^^^^^^^^^^^^
36+
| |
37+
| anonymous field declared here
38+
39+
error: anonymous structs are not allowed outside of unnamed struct or union fields
40+
--> $DIR/restrict_anonymous.rs:25:13
41+
|
42+
LL | _ : struct { field: u8 }
43+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
44+
45+
error: anonymous fields are not allowed outside of structs or unions
46+
--> $DIR/restrict_anonymous.rs:30:9
47+
|
48+
LL | _ : u8
49+
| -^^^^^
50+
| |
51+
| anonymous field declared here
52+
53+
error: anonymous unions are not allowed outside of unnamed struct or union fields
54+
--> $DIR/restrict_anonymous.rs:34:11
55+
|
56+
LL | static M: union { field: u8 } = 0;
57+
| ^^^^^^^^^^^^^^^^^^^ anonymous union declared here
58+
59+
error: anonymous unions are not allowed outside of unnamed struct or union fields
60+
--> $DIR/restrict_anonymous.rs:37:10
61+
|
62+
LL | type N = union { field: u8 };
63+
| ^^^^^^^^^^^^^^^^^^^ anonymous union declared here
64+
65+
error: anonymous structs are not allowed outside of unnamed struct or union fields
66+
--> $DIR/restrict_anonymous.rs:41:14
67+
|
68+
LL | const O: struct { field: u8 } = 0;
69+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
70+
71+
error: anonymous structs are not allowed outside of unnamed struct or union fields
72+
--> $DIR/restrict_anonymous.rs:44:13
73+
|
74+
LL | let p: [struct { field: u8 }; 1];
75+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
76+
77+
error: anonymous structs are not allowed outside of unnamed struct or union fields
78+
--> $DIR/restrict_anonymous.rs:47:13
79+
|
80+
LL | let q: (struct { field: u8 }, u8);
81+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
82+
83+
error: anonymous structs are not allowed outside of unnamed struct or union fields
84+
--> $DIR/restrict_anonymous.rs:50:20
85+
|
86+
LL | let cl = || -> struct { field: u8 } {};
87+
| ^^^^^^^^^^^^^^^^^^^^ anonymous struct declared here
88+
89+
error: anonymous structs are unimplemented
90+
--> $DIR/restrict_anonymous.rs:4:11
91+
|
92+
LL | fn f() -> struct { field: u8 } {}
93+
| ^^^^^^^^^^^^^^^^^^^^
94+
95+
error: anonymous structs are unimplemented
96+
--> $DIR/restrict_anonymous.rs:7:10
97+
|
98+
LL | fn f2(a: struct { field: u8 } ) {}
99+
| ^^^^^^^^^^^^^^^^^^^^
100+
101+
error: anonymous structs are unimplemented
102+
--> $DIR/restrict_anonymous.rs:11:12
103+
|
104+
LL | field: struct { field: u8 }
105+
| ^^^^^^^^^^^^^^^^^^^^
106+
107+
error: anonymous structs are unimplemented
108+
--> $DIR/restrict_anonymous.rs:18:10
109+
|
110+
LL | struct I(struct { field: u8 }, u8);
111+
| ^^^^^^^^^^^^^^^^^^^^
112+
113+
error: anonymous structs are unimplemented
114+
--> $DIR/restrict_anonymous.rs:22:7
115+
|
116+
LL | K(struct { field: u8 }),
117+
| ^^^^^^^^^^^^^^^^^^^^
118+
119+
error: anonymous structs are unimplemented
120+
--> $DIR/restrict_anonymous.rs:25:13
121+
|
122+
LL | _ : struct { field: u8 }
123+
| ^^^^^^^^^^^^^^^^^^^^
124+
125+
error: anonymous unions are unimplemented
126+
--> $DIR/restrict_anonymous.rs:34:11
127+
|
128+
LL | static M: union { field: u8 } = 0;
129+
| ^^^^^^^^^^^^^^^^^^^
130+
131+
error: anonymous unions are unimplemented
132+
--> $DIR/restrict_anonymous.rs:37:10
133+
|
134+
LL | type N = union { field: u8 };
135+
| ^^^^^^^^^^^^^^^^^^^
136+
137+
error: anonymous structs are unimplemented
138+
--> $DIR/restrict_anonymous.rs:44:13
139+
|
140+
LL | let p: [struct { field: u8 }; 1];
141+
| ^^^^^^^^^^^^^^^^^^^^
142+
143+
error: anonymous structs are unimplemented
144+
--> $DIR/restrict_anonymous.rs:47:13
145+
|
146+
LL | let q: (struct { field: u8 }, u8);
147+
| ^^^^^^^^^^^^^^^^^^^^
148+
149+
error: anonymous structs are unimplemented
150+
--> $DIR/restrict_anonymous.rs:50:20
151+
|
152+
LL | let cl = || -> struct { field: u8 } {};
153+
| ^^^^^^^^^^^^^^^^^^^^
154+
155+
error: anonymous structs are unimplemented
156+
--> $DIR/restrict_anonymous.rs:41:14
157+
|
158+
LL | const O: struct { field: u8 } = 0;
159+
| ^^^^^^^^^^^^^^^^^^^^
160+
161+
error[E0740]: unions may not contain fields that need dropping
162+
--> $DIR/restrict_anonymous.rs:11:5
163+
|
164+
LL | field: struct { field: u8 }
165+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
166+
|
167+
note: `std::mem::ManuallyDrop` can be used to wrap the type
168+
--> $DIR/restrict_anonymous.rs:11:5
169+
|
170+
LL | field: struct { field: u8 }
171+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
172+
173+
error: aborting due to 27 previous errors
174+
175+
For more information about this error, try `rustc --explain E0740`.

0 commit comments

Comments
 (0)