Skip to content

Commit 32c0cb0

Browse files
committed
Add union with default field values case test
In particular, there should be no additional errors (default field values for `union` fields are currently erroneously accepted).
1 parent e314b97 commit 32c0cb0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

tests/ui/structs/default-field-values/failures.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ enum E {
4949
Variant {} //~ ERROR the `#[default]` attribute may only be used on unit enum variants
5050
}
5151

52+
union U
53+
{
54+
x: i32 = 1,
55+
y: f32 = 2.,
56+
}
57+
5258
fn main () {
5359
let _ = Foo { .. }; // ok
5460
let _ = Foo::default(); // ok

tests/ui/structs/default-field-values/failures.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ LL | pub struct S;
2828
|
2929

3030
error: missing field `bar` in initializer
31-
--> $DIR/failures.rs:55:19
31+
--> $DIR/failures.rs:61:19
3232
|
3333
LL | let _ = Bar { .. };
3434
| ^ fields that do not have a defaulted value must be provided explicitly
3535

3636
error: missing field `bar` in initializer
37-
--> $DIR/failures.rs:56:27
37+
--> $DIR/failures.rs:62:27
3838
|
3939
LL | let _ = Bar { baz: 0, .. };
4040
| ^ fields that do not have a defaulted value must be provided explicitly
4141

4242
error[E0308]: mismatched types
43-
--> $DIR/failures.rs:60:17
43+
--> $DIR/failures.rs:66:17
4444
|
4545
LL | let _ = Rak(..);
4646
| --- ^^ expected `i32`, found `RangeFull`
@@ -53,19 +53,19 @@ note: tuple struct defined here
5353
LL | pub struct Rak(i32 = 42);
5454
| ^^^
5555
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
56-
--> $DIR/failures.rs:60:17
56+
--> $DIR/failures.rs:66:17
5757
|
5858
LL | let _ = Rak(..);
5959
| ^^
6060

6161
error[E0061]: this struct takes 1 argument but 2 arguments were supplied
62-
--> $DIR/failures.rs:62:13
62+
--> $DIR/failures.rs:68:13
6363
|
6464
LL | let _ = Rak(0, ..);
6565
| ^^^ -- unexpected argument #2 of type `RangeFull`
6666
|
6767
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
68-
--> $DIR/failures.rs:62:20
68+
--> $DIR/failures.rs:68:20
6969
|
7070
LL | let _ = Rak(0, ..);
7171
| ^^
@@ -81,13 +81,13 @@ LL + let _ = Rak(0);
8181
|
8282

8383
error[E0061]: this struct takes 1 argument but 2 arguments were supplied
84-
--> $DIR/failures.rs:64:13
84+
--> $DIR/failures.rs:70:13
8585
|
8686
LL | let _ = Rak(.., 0);
8787
| ^^^ -- unexpected argument #1 of type `RangeFull`
8888
|
8989
help: you might have meant to use `..` to skip providing a value for expected fields, but this is only supported on non-tuple struct literals; it is instead interpreted as a `std::ops::RangeFull` literal
90-
--> $DIR/failures.rs:64:17
90+
--> $DIR/failures.rs:70:17
9191
|
9292
LL | let _ = Rak(.., 0);
9393
| ^^

0 commit comments

Comments
 (0)