Originally, a type implementing Error
had to implement fn description(&self) -> &str
. This is no longer the case, and as of Rust 1.41, that method is actually deprecated. This is because Error
requires Debug + Display
, so the built-in solution is to just use .to_string()
.
Given this combination of factors, I believe it makes sense to add a #[derive(Error)]
to the compiler. This would behave in a similar manner to #[derive(Copy)]
, throwing a compiler error if Display
is not implemented. If a Display
impl is present, the code could expand by adding impl std::error::Error for Foo {}
.
Example error:
Current status with deriving Copy
without a Clone
impl:
#[derive(Copy)]
struct Foo;
error[E0277]: the trait bound `Foo: std::clone::Clone` is not satisfied
--> src/lib.rs:1:10
|
1 | #[derive(Copy)]
| ^^^^ the trait `std::clone::Clone` is not implemented for `Foo`
error: aborting due to previous error
A similar error could be thrown when deriving Error
without a Display
impl:
#[derive(Error)]
struct Foo;
error[E0277]: the trait bound `Foo: std::fmt::Display` is not satisfied
--> src/lib.rs:1:10
|
1 | #[derive(Error)]
| ^^^^^ the trait `std::fmt::Display` is not implemented for `Foo`
error: aborting due to previous error
Thoughts?
NB: A Debug
impl would also be required, per Error
's definition, giving similar errors.