-
-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests of #[serde(default)] attribute for units and unions
- Loading branch information
Showing
8 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(default)] | ||
union Union { | ||
f: 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,14 @@ | ||
error: #[serde(default)] can only be used on structs | ||
--> tests/ui/default-attribute/union.rs:4:9 | ||
| | ||
4 | #[serde(default)] | ||
| ^^^^^^^ | ||
|
||
error: Serde does not support derive for unions | ||
--> tests/ui/default-attribute/union.rs:4:1 | ||
| | ||
4 | / #[serde(default)] | ||
5 | | union Union { | ||
6 | | f: u8, | ||
7 | | } | ||
| |_^ |
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,9 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(default = "default_u")] | ||
union Union { | ||
f: 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,14 @@ | ||
error: #[serde(default = "...")] can only be used on structs | ||
--> tests/ui/default-attribute/union_path.rs:4:9 | ||
| | ||
4 | #[serde(default = "default_u")] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: Serde does not support derive for unions | ||
--> tests/ui/default-attribute/union_path.rs:4:1 | ||
| | ||
4 | / #[serde(default = "default_u")] | ||
5 | | union Union { | ||
6 | | f: u8, | ||
7 | | } | ||
| |_^ |
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,7 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(default)] | ||
struct Unit; | ||
|
||
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,7 @@ | ||
error: #[serde(default)] can only be used on structs that have fields | ||
--> tests/ui/default-attribute/unit.rs:3:10 | ||
| | ||
3 | #[derive(Deserialize)] | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) |
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,7 @@ | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(default = "default_u")] | ||
struct Unit; | ||
|
||
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,5 @@ | ||
error: #[serde(default = "...")] can only be used on structs that have fields | ||
--> tests/ui/default-attribute/unit_path.rs:4:9 | ||
| | ||
4 | #[serde(default = "default_u")] | ||
| ^^^^^^^^^^^^^^^^^^^^^ |