forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135703 - estebank:empty-dfv, r=compiler-errors Disallow `A { .. }` if `A` has no fields ``` error: `A` has no fields, `..` needs at least one default field in the struct definition --> $DIR/empty-struct.rs:16:17 | LL | let _ = A { .. }; | - ^^ | | | this type has no fields ```
- Loading branch information
Showing
3 changed files
with
72 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#![feature(default_field_values)] | ||
|
||
// If an API wants users to always use `..` even if they specify all the fields, they should use a | ||
// sentinel field. As of now, that field can't be made private so it is only constructable with this | ||
// syntax, but this might change in the future. | ||
|
||
struct A {} | ||
struct B(); | ||
struct C; | ||
struct D { | ||
x: i32, | ||
} | ||
struct E(i32); | ||
|
||
fn main() { | ||
let _ = A { .. }; //~ ERROR has no fields | ||
let _ = B { .. }; //~ ERROR has no fields | ||
let _ = C { .. }; //~ ERROR has no fields | ||
let _ = D { x: 0, .. }; | ||
let _ = E { 0: 0, .. }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: `A` has no fields, `..` needs at least one default field in the struct definition | ||
--> $DIR/empty-struct.rs:16:17 | ||
| | ||
LL | let _ = A { .. }; | ||
| - ^^ | ||
| | | ||
| this type has no fields | ||
|
||
error: `B` has no fields, `..` needs at least one default field in the struct definition | ||
--> $DIR/empty-struct.rs:17:17 | ||
| | ||
LL | let _ = B { .. }; | ||
| - ^^ | ||
| | | ||
| this type has no fields | ||
|
||
error: `C` has no fields, `..` needs at least one default field in the struct definition | ||
--> $DIR/empty-struct.rs:18:17 | ||
| | ||
LL | let _ = C { .. }; | ||
| - ^^ | ||
| | | ||
| this type has no fields | ||
|
||
error: aborting due to 3 previous errors | ||
|