-
-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2558 from Mingun/correct-span
Improve error reporting about mismatched signature in `with` and `default` attributes
- Loading branch information
Showing
27 changed files
with
628 additions
and
13 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
22 changes: 22 additions & 0 deletions
22
test_suite/tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.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,22 @@ | ||
//! Ensures that error message points to the path in attribute | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(tag = "tag", content = "content")] | ||
enum Enum { | ||
// Newtype variants does not use the provided path, so it is forbidden here | ||
// Newtype(#[serde(default = "main")] u8), | ||
Tuple( | ||
u8, | ||
#[serde(default = "main")] i8, | ||
), | ||
Struct { | ||
#[serde(default = "main")] | ||
f1: u8, | ||
f2: u8, | ||
#[serde(default = "main")] | ||
f3: i8, | ||
}, | ||
} | ||
|
||
fn main() {} |
35 changes: 35 additions & 0 deletions
35
test_suite/tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.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,35 @@ | ||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:11:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `i8` | ||
| `match` arms have incompatible types | ||
... | ||
11 | #[serde(default = "main")] i8, | ||
| ^^^^^^ expected `i8`, found `()` | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:14:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `u8` | ||
| `match` arms have incompatible types | ||
... | ||
14 | #[serde(default = "main")] | ||
| ^^^^^^ expected `u8`, found `()` | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_adjacently_tagged.rs:17:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `i8` | ||
| `match` arms have incompatible types | ||
... | ||
17 | #[serde(default = "main")] | ||
| ^^^^^^ expected `i8`, found `()` |
21 changes: 21 additions & 0 deletions
21
test_suite/tests/ui/default-attribute/incorrect_type_enum_externally_tagged.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,21 @@ | ||
//! Ensures that error message points to the path in attribute | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
enum Enum { | ||
// Newtype variants does not use the provided path, so it is forbidden here | ||
// Newtype(#[serde(default = "main")] u8), | ||
Tuple( | ||
u8, | ||
#[serde(default = "main")] i8, | ||
), | ||
Struct { | ||
#[serde(default = "main")] | ||
f1: u8, | ||
f2: u8, | ||
#[serde(default = "main")] | ||
f3: i8, | ||
}, | ||
} | ||
|
||
fn main() {} |
35 changes: 35 additions & 0 deletions
35
test_suite/tests/ui/default-attribute/incorrect_type_enum_externally_tagged.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,35 @@ | ||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:10:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `i8` | ||
| `match` arms have incompatible types | ||
... | ||
10 | #[serde(default = "main")] i8, | ||
| ^^^^^^ expected `i8`, found `()` | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:13:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `u8` | ||
| `match` arms have incompatible types | ||
... | ||
13 | #[serde(default = "main")] | ||
| ^^^^^^ expected `u8`, found `()` | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_externally_tagged.rs:16:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `i8` | ||
| `match` arms have incompatible types | ||
... | ||
16 | #[serde(default = "main")] | ||
| ^^^^^^ expected `i8`, found `()` |
19 changes: 19 additions & 0 deletions
19
test_suite/tests/ui/default-attribute/incorrect_type_enum_internally_tagged.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,19 @@ | ||
//! Ensures that error message points to the path in attribute | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(tag = "tag")] | ||
enum Enum { | ||
// Newtype variants does not use the provided path, so it is forbidden here | ||
// Newtype(#[serde(default = "main")] u8), | ||
// Tuple variants does not supported in internally tagged enums | ||
Struct { | ||
#[serde(default = "main")] | ||
f1: u8, | ||
f2: u8, | ||
#[serde(default = "main")] | ||
f3: i8, | ||
}, | ||
} | ||
|
||
fn main() {} |
23 changes: 23 additions & 0 deletions
23
test_suite/tests/ui/default-attribute/incorrect_type_enum_internally_tagged.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[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:11:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `u8` | ||
| `match` arms have incompatible types | ||
... | ||
11 | #[serde(default = "main")] | ||
| ^^^^^^ expected `u8`, found `()` | ||
|
||
error[E0308]: `match` arms have incompatible types | ||
--> tests/ui/default-attribute/incorrect_type_enum_internally_tagged.rs:14:27 | ||
| | ||
4 | #[derive(Deserialize)] | ||
| ----------- | ||
| | | ||
| this is found to be of type `i8` | ||
| `match` arms have incompatible types | ||
... | ||
14 | #[serde(default = "main")] | ||
| ^^^^^^ expected `i8`, found `()` |
22 changes: 22 additions & 0 deletions
22
test_suite/tests/ui/default-attribute/incorrect_type_enum_untagged.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,22 @@ | ||
//! Ensures that error message points to the path in attribute | ||
use serde_derive::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
#[serde(untagged)] | ||
enum Enum { | ||
// Newtype variants does not use the provided path, so it is forbidden here | ||
// Newtype(#[serde(default = "main")] u8), | ||
Tuple( | ||
u8, | ||
#[serde(default = "main")] i8, | ||
), | ||
Struct { | ||
#[serde(default = "main")] | ||
f1: u8, | ||
f2: u8, | ||
#[serde(default = "main")] | ||
f3: i8, | ||
}, | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.