Skip to content

Commit

Permalink
Fix redundant "Error doesn't implement Display" in fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 15, 2023
1 parent 7e5ff62 commit d7e3bdd
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 280 deletions.
7 changes: 7 additions & 0 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ fn fallback(input: &DeriveInput, error: syn::Error) -> TokenStream {

#[allow(unused_qualifications)]
impl #impl_generics std::error::Error for #ty #ty_generics #where_clause {}

#[allow(unused_qualifications)]
impl #impl_generics ::core::fmt::Display for #ty #ty_generics #where_clause {
fn fmt(&self, __formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::unreachable!()
}
}
}
}

Expand Down
14 changes: 0 additions & 14 deletions tests/ui/bad-field-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: #[error(transparent)] needs to go outside the enum or struct, not on an i
|
5 | pub struct Error(#[error(transparent)] std::io::Error);
| ^^^^^^^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/bad-field-attr.rs:5:12
|
5 | pub struct Error(#[error(transparent)] std::io::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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/concat-display.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,3 @@ error: expected string literal
| ------------------------- in this macro invocation
|
= note: this error originates in the macro `error_type` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/concat-display.rs:13:13
|
13 | error_type!(Error, "foo");
| ^^^^^ `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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/duplicate-enum-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: duplicate #[source] attribute
|
8 | #[source]
| ^^^^^^^^^

error[E0277]: `ErrorEnum` doesn't implement `std::fmt::Display`
--> tests/ui/duplicate-enum-source.rs:4:10
|
4 | pub enum ErrorEnum {
| ^^^^^^^^^ `ErrorEnum` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `ErrorEnum`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/duplicate-fmt.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: only one #[error(...)] attribute is allowed
|
5 | #[error("...")]
| ^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/duplicate-fmt.rs:6:12
|
6 | pub struct 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/duplicate-struct-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: duplicate #[source] attribute
|
7 | #[source]
| ^^^^^^^^^

error[E0277]: `ErrorStruct` doesn't implement `std::fmt::Display`
--> tests/ui/duplicate-struct-source.rs:4:12
|
4 | pub struct ErrorStruct {
| ^^^^^^^^^^^ `ErrorStruct` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `ErrorStruct`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/duplicate-transparent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: duplicate #[error(transparent)] attribute
|
5 | #[error(transparent)]
| ^^^^^^^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/duplicate-transparent.rs:6:12
|
6 | pub struct Error(anyhow::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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/from-backtrace-backtrace.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: deriving From requires no fields other than source and backtrace
|
9 | #[from]
| ^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/from-backtrace-backtrace.rs:8:12
|
8 | pub struct 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/from-not-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: #[from] is only supported on the source field, not any other field
|
7 | #[from]
| ^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/from-not-source.rs:4:12
|
4 | pub struct 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/invalid-input-impl-anyway.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: expected attribute arguments in parentheses: #[error(...)]
|
4 | #[error]
| ^^^^^

error[E0277]: `MyError` doesn't implement `std::fmt::Display`
--> tests/ui/invalid-input-impl-anyway.rs:5:12
|
5 | pub struct MyError;
| ^^^^^^^ `MyError` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `MyError`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
28 changes: 0 additions & 28 deletions tests/ui/lifetime.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,3 @@ error: non-static lifetimes are not allowed in the source of an error, because s
|
15 | Foo(#[from] Generic<&'a str>),
| ^^^^^^^^^^^^^^^^

error[E0277]: `Error<'a>` doesn't implement `std::fmt::Display`
--> tests/ui/lifetime.rs:6:8
|
6 | struct Error<'a>(#[from] Inner<'a>);
| ^^^^^^^^^ `Error<'a>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Error<'a>`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`

error[E0277]: `Enum<'a>` doesn't implement `std::fmt::Display`
--> tests/ui/lifetime.rs:13:6
|
13 | enum Enum<'a> {
| ^^^^^^^^ `Enum<'a>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Enum<'a>`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/missing-fmt.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: missing #[error("...")] display attribute
|
7 | B(usize),
| ^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/missing-fmt.rs:4:10
|
4 | pub enum 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/transparent-display.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: cannot have both #[error(transparent)] and a display attribute
|
5 | #[error("...")]
| ^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/transparent-display.rs:6:12
|
6 | pub struct Error(anyhow::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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/transparent-enum-many.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,3 @@ error: #[error(transparent)] requires exactly one field
5 | / #[error(transparent)]
6 | | Other(anyhow::Error, String),
| |________________________________^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/transparent-enum-many.rs:4:10
|
4 | pub enum 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/transparent-enum-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: transparent variant can't contain #[source]
|
6 | Other(#[source] anyhow::Error),
| ^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/transparent-enum-source.rs:4:10
|
4 | pub enum 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/transparent-struct-many.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: #[error(transparent)] requires exactly one field
|
4 | #[error(transparent)]
| ^^^^^^^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/transparent-struct-many.rs:5:12
|
5 | pub struct 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/transparent-struct-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: transparent error struct can't contain #[source]
|
5 | pub struct Error(#[source] anyhow::Error);
| ^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/transparent-struct-source.rs:5:12
|
5 | pub struct Error(#[source] anyhow::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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/unexpected-field-fmt.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: not expected here; the #[error(...)] attribute belongs on top of a struct
|
6 | #[error("...")]
| ^^^^^^^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/unexpected-field-fmt.rs:4:10
|
4 | pub enum 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/unexpected-struct-source.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ error: not expected here; the #[source] attribute belongs on a specific field
|
4 | #[source]
| ^^^^^^^^^

error[E0277]: `Error` doesn't implement `std::fmt::Display`
--> tests/ui/unexpected-struct-source.rs:5:12
|
5 | pub struct 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`
14 changes: 0 additions & 14 deletions tests/ui/union.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ error: union as errors are not supported
7 | | }
| |_^

error[E0277]: `U` doesn't implement `std::fmt::Display`
--> tests/ui/union.rs:4:11
|
4 | pub union U {
| ^ `U` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `U`
= 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
|
| pub trait Error: Debug + Display {
| ^^^^^^^ required by this bound in `Error`

error[E0277]: `U` doesn't implement `Debug`
--> tests/ui/union.rs:4:11
|
Expand Down

0 comments on commit d7e3bdd

Please sign in to comment.