Skip to content

Commit

Permalink
Add regression test for issue 113
Browse files Browse the repository at this point in the history
This does not currently compile.

    error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
      --> tests/test_transparent.rs:63:14
       |
    63 |     #[derive(Error, Debug)]
       |              ^^^^^
       |
    note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 65:18...
      --> tests/test_transparent.rs:65:18
       |
    65 |     struct Error<'a> {
       |                  ^^
    note: ...so that the types are compatible
      --> tests/test_transparent.rs:63:14
       |
    63 |     #[derive(Error, Debug)]
       |              ^^^^^
       = note: expected `&test_non_static::ErrorKind<'_>`
                  found `&test_non_static::ErrorKind<'a>`
       = note: but, the lifetime must be valid for the static lifetime...
    note: ...so that the type `test_non_static::ErrorKind<'_>` will meet its required lifetime bounds
      --> tests/test_transparent.rs:63:14
       |
    63 |     #[derive(Error, Debug)]
       |              ^^^^^
       = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
  • Loading branch information
dtolnay committed May 22, 2021
1 parent ee2a47d commit 51a1ff6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,24 @@ fn test_anyhow() {
assert_eq!("outer", error.to_string());
assert_eq!("inner", error.source().unwrap().to_string());
}

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

#[derive(Error, Debug)]
enum ErrorKind<'a> {
#[error("unexpected token: {:?}", token)]
Unexpected { token: &'a str },
}

let error = Error {
inner: ErrorKind::Unexpected { token: "error" },
};
assert_eq!("unexpected token: \"error\"", error.to_string());
assert!(error.source().is_none());
}

0 comments on commit 51a1ff6

Please sign in to comment.