-
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.
Clarify error messages when using attributes in wrong place
- Loading branch information
Showing
3 changed files
with
305 additions
and
23 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
compatibility-tests/compile-fail/tests/ui/attribute-misuse.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,36 @@ | ||
mod enum_misuse { | ||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(display("display should not work here"))] | ||
#[snafu(source(from(XXXX, Box::new)))] | ||
#[snafu(source(true))] | ||
#[snafu(backtrace)] | ||
enum EnumError { | ||
#[snafu(display("an error variant"))] | ||
#[snafu(source(from(XXXX, Box::new)))] | ||
#[snafu(backtrace)] | ||
AVariant { | ||
#[snafu(display("display should not work here"))] | ||
#[snafu(visibility(pub))] | ||
a: String, | ||
}, | ||
} | ||
} | ||
|
||
mod struct_misuse { | ||
use snafu::Snafu; | ||
|
||
#[derive(Debug, Snafu)] | ||
enum UsableError {} | ||
|
||
#[derive(Debug, Snafu)] | ||
#[snafu(display("display should not work here"))] | ||
#[snafu(source(from(UsableError, Box::new)))] | ||
#[snafu(visibility(pub))] | ||
#[snafu(source(true))] | ||
#[snafu(backtrace)] | ||
struct StructError(Box<UsableError>); | ||
} | ||
|
||
fn main() {} |
71 changes: 71 additions & 0 deletions
71
compatibility-tests/compile-fail/tests/ui/attribute-misuse.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: 'display' attribute is only valid on variants of an enum deriving Snafu; attempted to place on this enum: | ||
--> $DIR/attribute-misuse.rs:9:10 | ||
| | ||
9 | enum EnumError { | ||
| ^^^^^^^^^ | ||
|
||
error: 'source(from)' attribute is only valid on individual fields; attempted to place on this enum: | ||
--> $DIR/attribute-misuse.rs:9:10 | ||
| | ||
9 | enum EnumError { | ||
| ^^^^^^^^^ | ||
|
||
error: 'source(bool)' attribute is only valid on individual fields; attempted to place on this enum: | ||
--> $DIR/attribute-misuse.rs:9:10 | ||
| | ||
9 | enum EnumError { | ||
| ^^^^^^^^^ | ||
|
||
error: 'backtrace' attribute is only valid on individual fields; attempted to place on this enum: | ||
--> $DIR/attribute-misuse.rs:9:10 | ||
| | ||
9 | enum EnumError { | ||
| ^^^^^^^^^ | ||
|
||
error: 'source' attribute is only valid on individual fields; attempted to place on this variant: | ||
--> $DIR/attribute-misuse.rs:13:9 | ||
| | ||
13 | AVariant { | ||
| ^^^^^^^^ | ||
|
||
error: 'backtrace' attribute is only valid on individual fields; attempted to place on this variant: | ||
--> $DIR/attribute-misuse.rs:13:9 | ||
| | ||
13 | AVariant { | ||
| ^^^^^^^^ | ||
|
||
error: 'display' attribute is only valid on variants of an enum deriving Snafu; attempted to place on this field: | ||
--> $DIR/attribute-misuse.rs:16:13 | ||
| | ||
16 | a: String, | ||
| ^ | ||
|
||
error: 'visibility' attribute is only valid on an enum deriving Snafu and its variants; attempted to place on this field: | ||
--> $DIR/attribute-misuse.rs:16:13 | ||
| | ||
16 | a: String, | ||
| ^ | ||
|
||
error: 'display' attribute is only valid on variants of an enum deriving Snafu; attempted to place on this struct: | ||
--> $DIR/attribute-misuse.rs:33:12 | ||
| | ||
33 | struct StructError(Box<UsableError>); | ||
| ^^^^^^^^^^^ | ||
|
||
error: 'visibility' attribute is only valid on an enum deriving Snafu and its variants; attempted to place on this struct: | ||
--> $DIR/attribute-misuse.rs:33:12 | ||
| | ||
33 | struct StructError(Box<UsableError>); | ||
| ^^^^^^^^^^^ | ||
|
||
error: 'source(bool)' attribute is only valid on individual fields; attempted to place on this struct: | ||
--> $DIR/attribute-misuse.rs:33:12 | ||
| | ||
33 | struct StructError(Box<UsableError>); | ||
| ^^^^^^^^^^^ | ||
|
||
error: 'backtrace' attribute is only valid on individual fields; attempted to place on this struct: | ||
--> $DIR/attribute-misuse.rs:33:12 | ||
| | ||
33 | struct StructError(Box<UsableError>); | ||
| ^^^^^^^^^^^ |
Oops, something went wrong.