Skip to content

Commit 0889c59

Browse files
committed
Add tests that ensures that error reported for a path for with and default attributes
1 parent 61698c0 commit 0889c59

16 files changed

+501
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Ensures that error message points to the path in attribute
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Deserialize)]
5+
#[serde(tag = "tag", content = "content")]
6+
enum Enum {
7+
// Newtype variants does not use the provided path, so it is forbidden here
8+
// Newtype(#[serde(default = "main")] u8),
9+
Tuple(
10+
u8,
11+
#[serde(default = "main")] i8,
12+
),
13+
Struct {
14+
#[serde(default = "main")]
15+
f1: u8,
16+
f2: u8,
17+
#[serde(default = "main")]
18+
f3: i8,
19+
},
20+
}
21+
22+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:11:27
3+
|
4+
4 | #[derive(Deserialize)]
5+
| -----------
6+
| |
7+
| this is found to be of type `i8`
8+
| `match` arms have incompatible types
9+
...
10+
11 | #[serde(default = "main")] i8,
11+
| ^^^^^^ expected `i8`, found `()`
12+
13+
error[E0308]: `match` arms have incompatible types
14+
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:14:27
15+
|
16+
4 | #[derive(Deserialize)]
17+
| -----------
18+
| |
19+
| this is found to be of type `u8`
20+
| `match` arms have incompatible types
21+
...
22+
14 | #[serde(default = "main")]
23+
| ^^^^^^ expected `u8`, found `()`
24+
25+
error[E0308]: `match` arms have incompatible types
26+
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:17:27
27+
|
28+
4 | #[derive(Deserialize)]
29+
| -----------
30+
| |
31+
| this is found to be of type `i8`
32+
| `match` arms have incompatible types
33+
...
34+
17 | #[serde(default = "main")]
35+
| ^^^^^^ expected `i8`, found `()`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Ensures that error message points to the path in attribute
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Deserialize)]
5+
enum Enum {
6+
// Newtype variants does not use the provided path, so it is forbidden here
7+
// Newtype(#[serde(default = "main")] u8),
8+
Tuple(
9+
u8,
10+
#[serde(default = "main")] i8,
11+
),
12+
Struct {
13+
#[serde(default = "main")]
14+
f1: u8,
15+
f2: u8,
16+
#[serde(default = "main")]
17+
f3: i8,
18+
},
19+
}
20+
21+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:10:27
3+
|
4+
4 | #[derive(Deserialize)]
5+
| -----------
6+
| |
7+
| this is found to be of type `i8`
8+
| `match` arms have incompatible types
9+
...
10+
10 | #[serde(default = "main")] i8,
11+
| ^^^^^^ expected `i8`, found `()`
12+
13+
error[E0308]: `match` arms have incompatible types
14+
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:13:27
15+
|
16+
4 | #[derive(Deserialize)]
17+
| -----------
18+
| |
19+
| this is found to be of type `u8`
20+
| `match` arms have incompatible types
21+
...
22+
13 | #[serde(default = "main")]
23+
| ^^^^^^ expected `u8`, found `()`
24+
25+
error[E0308]: `match` arms have incompatible types
26+
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:16:27
27+
|
28+
4 | #[derive(Deserialize)]
29+
| -----------
30+
| |
31+
| this is found to be of type `i8`
32+
| `match` arms have incompatible types
33+
...
34+
16 | #[serde(default = "main")]
35+
| ^^^^^^ expected `i8`, found `()`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Ensures that error message points to the path in attribute
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Deserialize)]
5+
#[serde(tag = "tag")]
6+
enum Enum {
7+
// Newtype variants does not use the provided path, so it is forbidden here
8+
// Newtype(#[serde(default = "main")] u8),
9+
// Tuple variants does not supported in internally tagged enums
10+
Struct {
11+
#[serde(default = "main")]
12+
f1: u8,
13+
f2: u8,
14+
#[serde(default = "main")]
15+
f3: i8,
16+
},
17+
}
18+
19+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:11:27
3+
|
4+
4 | #[derive(Deserialize)]
5+
| -----------
6+
| |
7+
| this is found to be of type `u8`
8+
| `match` arms have incompatible types
9+
...
10+
11 | #[serde(default = "main")]
11+
| ^^^^^^ expected `u8`, found `()`
12+
13+
error[E0308]: `match` arms have incompatible types
14+
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:14:27
15+
|
16+
4 | #[derive(Deserialize)]
17+
| -----------
18+
| |
19+
| this is found to be of type `i8`
20+
| `match` arms have incompatible types
21+
...
22+
14 | #[serde(default = "main")]
23+
| ^^^^^^ expected `i8`, found `()`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Ensures that error message points to the path in attribute
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Deserialize)]
5+
#[serde(untagged)]
6+
enum Enum {
7+
// Newtype variants does not use the provided path, so it is forbidden here
8+
// Newtype(#[serde(default = "main")] u8),
9+
Tuple(
10+
u8,
11+
#[serde(default = "main")] i8,
12+
),
13+
Struct {
14+
#[serde(default = "main")]
15+
f1: u8,
16+
f2: u8,
17+
#[serde(default = "main")]
18+
f3: i8,
19+
},
20+
}
21+
22+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0308]: `match` arms have incompatible types
2+
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:11:27
3+
|
4+
4 | #[derive(Deserialize)]
5+
| -----------
6+
| |
7+
| this is found to be of type `i8`
8+
| `match` arms have incompatible types
9+
...
10+
11 | #[serde(default = "main")] i8,
11+
| ^^^^^^ expected `i8`, found `()`
12+
13+
error[E0308]: `match` arms have incompatible types
14+
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:14:27
15+
|
16+
4 | #[derive(Deserialize)]
17+
| -----------
18+
| |
19+
| this is found to be of type `u8`
20+
| `match` arms have incompatible types
21+
...
22+
14 | #[serde(default = "main")]
23+
| ^^^^^^ expected `u8`, found `()`
24+
25+
error[E0308]: `match` arms have incompatible types
26+
--> tests/ui/default-attribute/incorrect_type_enum_untagged.rs:17:27
27+
|
28+
4 | #[derive(Deserialize)]
29+
| -----------
30+
| |
31+
| this is found to be of type `i8`
32+
| `match` arms have incompatible types
33+
...
34+
17 | #[serde(default = "main")]
35+
| ^^^^^^ expected `i8`, found `()`
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//! Ensures that error message points to the path in attribute
2+
use serde_derive::Deserialize;
3+
4+
#[derive(Deserialize)]
5+
#[serde(default = "main")]
6+
struct Newtype(#[serde(default = "main")] u8);
7+
8+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0308]: mismatched types
2+
--> tests/ui/default-attribute/incorrect_type_newtype.rs:5:19
3+
|
4+
5 | #[serde(default = "main")]
5+
| ^^^^^^
6+
| |
7+
| expected `Newtype`, found `()`
8+
| expected due to this
9+
10+
error[E0308]: `match` arms have incompatible types
11+
--> tests/ui/default-attribute/incorrect_type_newtype.rs:6:34
12+
|
13+
4 | #[derive(Deserialize)]
14+
| -----------
15+
| |
16+
| this is found to be of type `u8`
17+
| `match` arms have incompatible types
18+
5 | #[serde(default = "main")]
19+
6 | struct Newtype(#[serde(default = "main")] u8);
20+
| ^^^^^^ expected `u8`, found `()`
21+
22+
error[E0308]: mismatched types
23+
--> tests/ui/default-attribute/incorrect_type_newtype.rs:5:19
24+
|
25+
5 | #[serde(default = "main")]
26+
| ^^^^^^ expected `Newtype`, found `()`
27+
6 | struct Newtype(#[serde(default = "main")] u8);
28+
| ------- expected due to this
29+
30+
error[E0308]: mismatched types
31+
--> tests/ui/default-attribute/incorrect_type_newtype.rs:6:34
32+
|
33+
4 | #[derive(Deserialize)]
34+
| ----------- expected due to the type of this binding
35+
5 | #[serde(default = "main")]
36+
6 | struct Newtype(#[serde(default = "main")] u8);
37+
| ^^^^^^ expected `u8`, found `()`

0 commit comments

Comments
 (0)