Skip to content

Commit

Permalink
Add error checks for duplicate attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tjkirch committed Jul 22, 2019
1 parent 3e9e95d commit 6cb4381
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 37 deletions.
48 changes: 48 additions & 0 deletions compatibility-tests/compile-fail/tests/ui/attribute-duplication.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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(from(EnumError, Box::new)))]
#[snafu(backtrace(delegate))]
source2: Box<EnumError>,
#[snafu(source)]
#[snafu(backtrace(delegate))]
source3: String,
#[snafu(source)]
#[snafu(backtrace(delegate))]
source4: 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() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
error: Multiple 'visibility' attributes are not supported on an error enum; found a duplicate here:
--> $DIR/attribute-duplication.rs:7:10
|
7 | enum EnumError {
| ^^^^^^^^^

error: Multiple 'source' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:21:13
|
21 | source3: String,
| ^^^^^^^

error: Multiple 'source' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:24:13
|
24 | source4: String,
| ^^^^^^^

error: Multiple 'backtrace' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:29:13
|
29 | backtrace2: String,
| ^^^^^^^^^^

error: Multiple 'backtrace' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:31:13
|
31 | backtrace3: String,
| ^^^^^^^^^^

error: Multiple 'backtrace(delegate)' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:21:13
|
21 | source3: String,
| ^^^^^^^

error: Multiple 'backtrace(delegate)' attributes are not supported within an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:24:13
|
24 | source4: String,
| ^^^^^^^

error: Cannot have 'backtrace' and 'backtrace(delegate)' fields in the same error variant
--> $DIR/attribute-duplication.rs:27:13
|
27 | backtrace1: String,
| ^^^^^^^^^^

error: Cannot have 'backtrace' and 'backtrace(delegate)' fields in the same error variant
--> $DIR/attribute-duplication.rs:15:13
|
15 | source: Box<EnumError>,
| ^^^^^^

error: Multiple 'display' attributes are not supported on an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:12:9
|
12 | AVariant {
| ^^^^^^^^

error: Multiple 'visibility' attributes are not supported on an error variant; found a duplicate here:
--> $DIR/attribute-duplication.rs:12:9
|
12 | AVariant {
| ^^^^^^^^

error: Multiple 'source(from)' attributes are not supported on an error struct; found a duplicate here:
--> $DIR/attribute-duplication.rs:44:25
|
44 | #[snafu(source(from(UsableError, Box::new)))]
| ^^^^^^^^^^^
Loading

0 comments on commit 6cb4381

Please sign in to comment.