You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thiserror works well with recursive error types, and this snippet compiles with no error:
use std::error::Error;use thiserror::Error;// 1.0.63#[derive(Debug,Error)]pubenumMyError{#[error("Recurse")]Recurse(#[source]Box<MyError>),#[error("Payload")]Payload(&'static str),}fnmain(){let _:&dynError = &MyError::Payload("Hello");}
But when one uses an error that is parametrized over his content, it causes an overflow in type evaluation:
use std::error::Error;use thiserror::Error;// 1.0.63#[derive(Debug,Error)]pubenumMyError<Payload>{#[error("Recurse")]Recurse(#[source]Box<MyError<Payload>>),#[error("Payload")]Payload(Payload),}fnmain(){let _:&dynError = &MyError::Payload("Hello");}
Compiling playground v0.0.1 (/playground)
error[E0275]: overflow evaluating the requirement `Box<MyError<&str>>: std::error::Error`
--> src/main.rs:15:25
|
15 | let _: &dyn Error = &MyError::Payload("Hello");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: required for `MyError<&str>` to implement `std::error::Error`
--> src/main.rs:5:17
|
5 | #[derive(Debug, Error)]
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro
6 | enum MyError<Payload> {
| ^^^^^^^^^^^^^^^^
= note: required for the cast from `&MyError<&str>` to `&dyn std::error::Error`
= note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0275`.
error: could not compile `playground` (bin "playground") due to 1 previous error
I can easily implement by myself, but often this is not possible due to too many variants
thiserror
works well with recursive error types, and this snippet compiles with no error:But when one uses an error that is parametrized over his content, it causes an overflow in type evaluation:
I can easily implement by myself, but often this is not possible due to too many variants
Is this an hard limitation?
The text was updated successfully, but these errors were encountered: