Skip to content

Commit

Permalink
Add tests of #[serde(default)] attribute for units and unions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Aug 7, 2023
1 parent 05a5b7e commit 61698c0
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test_suite/tests/ui/default-attribute/union.rs
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() {}
14 changes: 14 additions & 0 deletions test_suite/tests/ui/default-attribute/union.stderr
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 | | }
| |_^
9 changes: 9 additions & 0 deletions test_suite/tests/ui/default-attribute/union_path.rs
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() {}
14 changes: 14 additions & 0 deletions test_suite/tests/ui/default-attribute/union_path.stderr
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 | | }
| |_^
7 changes: 7 additions & 0 deletions test_suite/tests/ui/default-attribute/unit.rs
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() {}
7 changes: 7 additions & 0 deletions test_suite/tests/ui/default-attribute/unit.stderr
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)
7 changes: 7 additions & 0 deletions test_suite/tests/ui/default-attribute/unit_path.rs
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() {}
5 changes: 5 additions & 0 deletions test_suite/tests/ui/default-attribute/unit_path.stderr
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")]
| ^^^^^^^^^^^^^^^^^^^^^

0 comments on commit 61698c0

Please sign in to comment.