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
This seems pretty reasonable, but when compiling I get the error:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/main.rs:5:10
|
5 | #[derive(thiserror::Error, Debug)]
| ^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 6:12...
--> src/main.rs:6:12
|
6 | enum Error<'a> {
| ^^
note: ...so that the types are compatible
--> src/main.rs:5:10
|
5 | #[derive(thiserror::Error, Debug)]
| ^^^^^^^^^^^^^^^^
= note: expected `&Error<'_>`
found `&Error<'a>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `SomeError<&str>` will meet its required lifetime bounds
--> src/main.rs:7:13
|
7 | #[error("SomeError occured")]
| ^^^^^^^^^^^^^^^^^^^
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
This error is pretty tricky to decipher. It also does not occur when the type argument to SomeError<T> does not contain a lifetime (SomeError<String> works fine). The error can be solved by removing the #[from] and instead implementing From manually:
For posterity I will include the results of cargo-expand. The error above mentions that SomeError<&str> does not meet the lifetime bounds somewhere (likely in the From impl), but ctrl + F shows that this type does not appear anywhere (which adds to my confusion).
I have a minimal reproducible example of some simplified code that I am using:
This seems pretty reasonable, but when compiling I get the error:
This error is pretty tricky to decipher. It also does not occur when the type argument to
SomeError<T>
does not contain a lifetime (SomeError<String>
works fine). The error can be solved by removing the#[from]
and instead implementingFrom
manually:For posterity I will include the results of
cargo-expand
. The error above mentions thatSomeError<&str>
does not meet the lifetime bounds somewhere (likely in theFrom
impl), but ctrl + F shows that this type does not appear anywhere (which adds to my confusion).rustc 1.48.0 (7eac88abb 2020-11-16)
thiserror = "1.0.22"
If someone can point me in the correct direction in the library I'm willing to take a stab at solving this issue.
The text was updated successfully, but these errors were encountered: