-
-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow #[serde(default)] on tuple structs
- Loading branch information
Showing
13 changed files
with
230 additions
and
60 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
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
7 changes: 0 additions & 7 deletions
7
test_suite/tests/ui/default-attribute/nameless_struct_fields.rs
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
test_suite/tests/ui/default-attribute/nameless_struct_fields.stderr
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
test_suite/tests/ui/default-attribute/nameless_struct_fields_path.rs
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
test_suite/tests/ui/default-attribute/nameless_struct_fields_path.stderr
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
use serde_derive::Deserialize; | ||
|
||
/// No errors expected | ||
#[derive(Deserialize)] | ||
struct T0(u8, u8); | ||
|
||
/// No errors expected: | ||
/// - if both fields are provided, both gets value from data | ||
/// - if only one field is provided, the second gets default value | ||
#[derive(Deserialize)] | ||
struct T1(u8, #[serde(default)] u8); | ||
|
||
/// Errors expected -- the first field can get default value only if sequence is | ||
/// empty, but that mean that all other fields cannot be deserialized without | ||
/// errors, so the `#[serde(default)]` attribute is superfluous | ||
#[derive(Deserialize)] | ||
struct T2(#[serde(default)] u8, u8, u8); | ||
|
||
/// No errors expected: | ||
/// - if both fields are provided, both gets value from data | ||
/// - if only one field is provided, the second gets default value | ||
/// - if none fields are provided, both gets default value | ||
#[derive(Deserialize)] | ||
struct T3(#[serde(default)] u8, #[serde(default)] u8); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T4(u8, u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T5(#[serde(default)] u8, u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T6(u8, #[serde(default)] u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T7(#[serde(default)] u8, #[serde(default)] u8); | ||
|
||
fn main() {} |
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,11 @@ | ||
error: struct or field must have #[serde(default)] because previous field 0 have #[serde(default)] | ||
--> tests/ui/default-attribute/tuple_struct.rs:17:33 | ||
| | ||
17 | struct T2(#[serde(default)] u8, u8, u8); | ||
| ^^ | ||
|
||
error: struct or field must have #[serde(default)] because previous field 0 have #[serde(default)] | ||
--> tests/ui/default-attribute/tuple_struct.rs:17:37 | ||
| | ||
17 | struct T2(#[serde(default)] u8, u8, u8); | ||
| ^^ |
77 changes: 77 additions & 0 deletions
77
test_suite/tests/ui/default-attribute/tuple_struct_path.rs
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,77 @@ | ||
use serde_derive::Deserialize; | ||
|
||
fn d<T>() -> T { | ||
unimplemented!() | ||
} | ||
|
||
/// No errors expected: | ||
/// - if both fields are provided, both gets value from data | ||
/// - if only one field is provided, the second gets default value | ||
#[derive(Deserialize)] | ||
struct T1(u8, #[serde(default = "d")] u8); | ||
|
||
/// Errors expected -- the first field can get default value only if sequence is | ||
/// empty, but that mean that all other fields cannot be deserialized without | ||
/// errors, so the `#[serde(default)]` attribute is superfluous | ||
#[derive(Deserialize)] | ||
struct T2(#[serde(default = "d")] u8, u8, u8); | ||
|
||
/// No errors expected: | ||
/// - if both fields are provided, both gets value from data | ||
/// - if only one field is provided, the second gets default value | ||
/// - if none fields are provided, both gets default value | ||
#[derive(Deserialize)] | ||
struct T3(#[serde(default = "d")] u8, #[serde(default = "d")] u8); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T1D(#[serde(default = "d")] u8, u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T2D(u8, #[serde(default = "d")] u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize, Default)] | ||
#[serde(default)] | ||
struct T3D(#[serde(default = "d")] u8, #[serde(default = "d")] u8); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T1Path(#[serde(default)] u8, u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T2Path(u8, #[serde(default)] u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T3Path(#[serde(default)] u8, #[serde(default)] u8); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T1PathD(#[serde(default = "d")] u8, u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T2PathD(u8, #[serde(default = "d")] u8); | ||
|
||
/// No errors expected -- missing fields gets default values | ||
#[derive(Deserialize)] | ||
#[serde(default = "d")] | ||
struct T3PathD(#[serde(default = "d")] u8, #[serde(default = "d")] u8); | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
test_suite/tests/ui/default-attribute/tuple_struct_path.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,11 @@ | ||
error: struct or field must have #[serde(default)] because previous field 0 have #[serde(default)] | ||
--> tests/ui/default-attribute/tuple_struct_path.rs:17:39 | ||
| | ||
17 | struct T2(#[serde(default = "d")] u8, u8, u8); | ||
| ^^ | ||
|
||
error: struct or field must have #[serde(default)] because previous field 0 have #[serde(default)] | ||
--> tests/ui/default-attribute/tuple_struct_path.rs:17:43 | ||
| | ||
17 | struct T2(#[serde(default = "d")] u8, u8, u8); | ||
| ^^ |