-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #134539 - estebank:restrict-non_exhaustive, r=jieyouxu
Restrict `#[non_exaustive]` on structs with default field values Do not allow users to apply `#[non_exaustive]` to a struct when they have also used default field values.
- Loading branch information
Showing
5 changed files
with
78 additions
and
3 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
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,18 @@ | ||
#![feature(default_field_values)] | ||
|
||
#[derive(Default)] | ||
#[non_exhaustive] //~ ERROR `#[non_exhaustive]` can't be used to annotate items with default field values | ||
struct Foo { | ||
x: i32 = 42 + 3, | ||
} | ||
|
||
#[derive(Default)] | ||
enum Bar { | ||
#[non_exhaustive] | ||
#[default] | ||
Baz { //~ ERROR default variant must be exhaustive | ||
x: i32 = 42 + 3, | ||
} | ||
} | ||
|
||
fn main () {} |
23 changes: 23 additions & 0 deletions
23
tests/ui/structs/default-field-values-non_exhaustive.stderr
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,23 @@ | ||
error: default variant must be exhaustive | ||
--> $DIR/default-field-values-non_exhaustive.rs:13:5 | ||
| | ||
LL | #[non_exhaustive] | ||
| ----------------- declared `#[non_exhaustive]` here | ||
LL | #[default] | ||
LL | Baz { | ||
| ^^^ | ||
| | ||
= help: consider a manual implementation of `Default` | ||
|
||
error: `#[non_exhaustive]` can't be used to annotate items with default field values | ||
--> $DIR/default-field-values-non_exhaustive.rs:4:1 | ||
| | ||
LL | #[non_exhaustive] | ||
| ^^^^^^^^^^^^^^^^^ | ||
LL | / struct Foo { | ||
LL | | x: i32 = 42 + 3, | ||
LL | | } | ||
| |_- this struct has default field values | ||
|
||
error: aborting due to 2 previous errors | ||
|