Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifetimes and #[error(transparent)] #113

Closed
ExpHP opened this issue Dec 16, 2020 · 1 comment · Fixed by #134
Closed

Lifetimes and #[error(transparent)] #113

ExpHP opened this issue Dec 16, 2020 · 1 comment · Fixed by #134

Comments

@ExpHP
Copy link

ExpHP commented Dec 16, 2020

Lifetimes appear to interfere with the use of #[error(transparent)]:

use thiserror::Error;

#[derive(Error, Debug)]
#[error(transparent)]
pub struct Error<'a> {
    inner: ErrorKind<'a>,
}

#[derive(Error, Debug)]
pub enum ErrorKind<'a> {
    #[error("unexpected token: {:?}", .token)]
    Unexpected { token: &'a str },
}
   Compiling ecl-parser v0.1.0 (/mnt/f/asd/clone/ecl-parse)
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
 --> src/bin/lol.rs:3:10
  |
3 | #[derive(Error, Debug)]
  |          ^^^^^
  |
note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 5:18...
 --> src/bin/lol.rs:5:18
  |
5 | pub struct Error<'a> {
  |                  ^^
note: ...so that the types are compatible
 --> src/bin/lol.rs:3:10
  |
3 | #[derive(Error, Debug)]
  |          ^^^^^
  = note: expected `&ErrorKind<'_>`
             found `&ErrorKind<'a>`
  = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `ErrorKind<'_>` will meet its required lifetime bounds
 --> src/bin/lol.rs:3:10
  |
3 | #[derive(Error, Debug)]
  |          ^^^^^
  = 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
  • rustc 1.46.0 (04488afe3 2020-08-24)
  • thiserror 1.0.22
@dtolnay
Copy link
Owner

dtolnay commented May 22, 2021

Thanks — I've published a fix in 1.0.25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants