-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display impl for empty enum and non provided enum (#11)
* Add no_display attribute * Add tests with trybuild * Fix doc
- Loading branch information
Showing
18 changed files
with
333 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
#[test] | ||
fn compile_tests() { | ||
let t = trybuild::TestCases::new(); | ||
t.pass("compile_tests/empty.rs"); | ||
t.pass("compile_tests/one_comment.rs"); | ||
t.pass("compile_tests/one_param.rs"); | ||
t.compile_fail("compile_tests/one_non_signed.rs"); | ||
t.pass("compile_tests/multiple_variant.rs"); | ||
t.compile_fail("compile_tests/multiple_non_signed.rs"); | ||
t.compile_fail("compile_tests/multiple_one_non_signed.rs"); | ||
t.pass("compile_tests/no_display.rs"); | ||
if rustversion::cfg!(since(1.68.0)) { | ||
t.compile_fail("compile_tests/no_display_no_impl.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,4 @@ | ||
#[derive(Debug, onlyerror::Error)] | ||
enum Error {} | ||
|
||
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,8 @@ | ||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
First, | ||
Second(usize), | ||
Third { key: String, value: Vec<usize> }, | ||
} | ||
|
||
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,5 @@ | ||
error: Required error message is missing | ||
--> compile_tests/multiple_non_signed.rs:3:5 | ||
| | ||
3 | First, | ||
| ^^^^^ |
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 @@ | ||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
/// First | ||
First, | ||
#[error("Second with {0}")] | ||
Second(usize), | ||
Third { | ||
key: String, | ||
value: Vec<usize>, | ||
}, | ||
} | ||
|
||
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,5 @@ | ||
error: Required error message is missing | ||
--> compile_tests/multiple_one_non_signed.rs:7:5 | ||
| | ||
7 | Third { | ||
| ^^^^^ |
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 @@ | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
/// First | ||
First, | ||
#[error("Second with {0}")] | ||
Second(usize), | ||
#[error("Third with {key} and {value:?}")] | ||
Third { key: String, value: Vec<usize> }, | ||
} | ||
|
||
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,17 @@ | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug, onlyerror::Error)] | ||
#[no_display] | ||
enum Error { | ||
First, | ||
Second(usize), | ||
Third { key: String, value: Vec<usize> }, | ||
} | ||
|
||
impl core::fmt::Display for Error { | ||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> { | ||
write!(f, "Should work") | ||
} | ||
} | ||
|
||
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,14 @@ | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug, onlyerror::Error)] | ||
#[no_display] | ||
enum Error { | ||
/// First | ||
First, | ||
#[error("Second with {0}")] | ||
Second(usize), | ||
#[error("Third with {key} and {value:?}")] | ||
Third { key: String, value: Vec<usize> }, | ||
} | ||
|
||
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,11 @@ | ||
error[E0277]: `Error` doesn't implement `std::fmt::Display` | ||
--> compile_tests/no_display_no_impl.rs:3:17 | ||
| | ||
3 | #[derive(Debug, onlyerror::Error)] | ||
| ^^^^^^^^^^^^^^^^ `Error` cannot be formatted with the default formatter | ||
| | ||
= help: the trait `std::fmt::Display` is not implemented for `Error` | ||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead | ||
note: required by a bound in `std::error::Error` | ||
--> $RUST/core/src/error.rs | ||
= note: this error originates in the derive macro `onlyerror::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,9 @@ | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
/// One | ||
One, | ||
} | ||
|
||
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,6 @@ | ||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
One, | ||
} | ||
|
||
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,5 @@ | ||
error: Required error message is missing | ||
--> compile_tests/one_non_signed.rs:3:5 | ||
| | ||
3 | One, | ||
| ^^^ |
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,9 @@ | ||
#![allow(dead_code)] | ||
|
||
#[derive(Debug, onlyerror::Error)] | ||
enum Error { | ||
#[error("One")] | ||
One, | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.