-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error checks for duplicate attributes
- Loading branch information
Showing
3 changed files
with
252 additions
and
37 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
compatibility-tests/compile-fail/tests/ui/attribute-duplication.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,45 @@ | ||
mod enum_duplication { | ||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(visibility(pub))] | ||
#[snafu(visibility(pub))] | ||
enum EnumError { | ||
#[snafu(display("an error variant"))] | ||
#[snafu(display("should not allow duplicate display"))] | ||
#[snafu(visibility(pub))] | ||
#[snafu(visibility(pub))] | ||
AVariant { | ||
#[snafu(source(from(EnumError, Box::new)))] | ||
#[snafu(backtrace(delegate))] | ||
source: Box<EnumError>, | ||
#[snafu(source)] | ||
#[snafu(backtrace(delegate))] | ||
source2: String, | ||
#[snafu(source)] | ||
#[snafu(backtrace(delegate))] | ||
source3: String, | ||
|
||
#[snafu(backtrace)] | ||
backtrace1: String, | ||
#[snafu(backtrace)] | ||
backtrace2: String, | ||
#[snafu(backtrace)] | ||
backtrace3: String, | ||
}, | ||
} | ||
} | ||
|
||
mod struct_duplication { | ||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
enum UsableError {} | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(source(from(UsableError, Box::new)))] | ||
#[snafu(source(from(UsableError, Box::new)))] | ||
struct StructError(Box<UsableError>); | ||
} | ||
|
||
fn main() {} |
71 changes: 71 additions & 0 deletions
71
compatibility-tests/compile-fail/tests/ui/attribute-duplication.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,71 @@ | ||
error: Only one field can be designated as 'visibility'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:7:10 | ||
| | ||
7 | enum EnumError { | ||
| ^^^^^^^^^ | ||
|
||
error: Only one field can be designated as 'source'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:18:13 | ||
| | ||
18 | source2: String, | ||
| ^^^^^^^ | ||
|
||
error: Only one field can be designated as 'source'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:21:13 | ||
| | ||
21 | source3: String, | ||
| ^^^^^^^ | ||
|
||
error: Only one field can be designated as 'backtrace'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:26:13 | ||
| | ||
26 | backtrace2: String, | ||
| ^^^^^^^^^^ | ||
|
||
error: Only one field can be designated as 'backtrace'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:28:13 | ||
| | ||
28 | backtrace3: String, | ||
| ^^^^^^^^^^ | ||
|
||
error: Only one field can be designated as 'backtrace(delegate)'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:18:13 | ||
| | ||
18 | source2: String, | ||
| ^^^^^^^ | ||
|
||
error: Only one field can be designated as 'backtrace(delegate)'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:21:13 | ||
| | ||
21 | source3: String, | ||
| ^^^^^^^ | ||
|
||
error: Cannot have 'backtrace' and 'backtrace(delegate)' fields in the same enum | ||
--> $DIR/attribute-duplication.rs:24:13 | ||
| | ||
24 | backtrace1: String, | ||
| ^^^^^^^^^^ | ||
|
||
error: Cannot have 'backtrace' and 'backtrace(delegate)' fields in the same enum | ||
--> $DIR/attribute-duplication.rs:15:13 | ||
| | ||
15 | source: Box<EnumError>, | ||
| ^^^^^^ | ||
|
||
error: Only one field can be designated as 'display'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:12:9 | ||
| | ||
12 | AVariant { | ||
| ^^^^^^^^ | ||
|
||
error: Only one field can be designated as 'visibility'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:12:9 | ||
| | ||
12 | AVariant { | ||
| ^^^^^^^^ | ||
|
||
error: Only one field can be designated as 'source(from)'; found a duplicate here: | ||
--> $DIR/attribute-duplication.rs:41:25 | ||
| | ||
41 | #[snafu(source(from(UsableError, Box::new)))] | ||
| ^^^^^^^^^^^ |
Oops, something went wrong.