-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add errors on invalid forward usage and compile_fail tests for them
- Loading branch information
1 parent
92ae1cb
commit 78d9d99
Showing
7 changed files
with
83 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use derive_more::Error; | ||
|
||
#[derive(Debug, Error)] | ||
#[error(forward)] | ||
enum Foo { | ||
Bar, | ||
Baz { | ||
source: Box<dyn Error + Send + 'static>, | ||
}, | ||
} | ||
|
||
impl ::core::fmt::Display for Foo { | ||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { | ||
write!(f, "") | ||
} | ||
} | ||
|
||
fn main() {} |
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,7 @@ | ||
error: `#[error(forward)]` cannot be used when an error has no source | ||
--> tests/compile_fail/error/forward_no_source_enum.rs:3:17 | ||
| | ||
3 | #[derive(Debug, Error)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) |
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,13 @@ | ||
use derive_more::Error; | ||
|
||
#[derive(Debug, Error)] | ||
#[error(forward)] | ||
struct Foo; | ||
|
||
impl ::core::fmt::Display for Foo { | ||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { | ||
write!(f, "") | ||
} | ||
} | ||
|
||
fn main() {} |
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,7 @@ | ||
error: `#[error(forward)]` cannot be used when an error has no source | ||
--> tests/compile_fail/error/forward_no_source_struct.rs:3:17 | ||
| | ||
3 | #[derive(Debug, Error)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) |
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 @@ | ||
use derive_more::Error; | ||
|
||
#[derive(Debug, Error)] | ||
enum Foo { | ||
#[error(forward)] | ||
Bar, | ||
#[error(forward)] | ||
Baz { | ||
source: Box<dyn Error + Send + 'static>, | ||
}, | ||
} | ||
|
||
impl ::core::fmt::Display for Foo { | ||
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { | ||
write!(f, "") | ||
} | ||
} | ||
|
||
fn main() {} |
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,7 @@ | ||
error: `#[error(forward)]` cannot be used when an error has no source | ||
--> tests/compile_fail/error/forward_no_source_variant.rs:3:17 | ||
| | ||
3 | #[derive(Debug, Error)] | ||
| ^^^^^ | ||
| | ||
= note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) |