Add ui test of Generic<&'a str> source

This commit is contained in:
David Tolnay 2020-12-26 17:33:51 -08:00
parent 0859205018
commit d30890b4f7
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,4 @@
use std::fmt::Debug;
use thiserror::Error;
#[derive(Error, Debug)]
@ -8,6 +9,16 @@ struct Error<'a>(#[from] Inner<'a>);
#[error("{0}")]
struct Inner<'a>(&'a str);
#[derive(Error, Debug)]
enum Enum<'a> {
#[error("error")]
Foo(#[from] Generic<&'a str>),
}
#[derive(Error, Debug)]
#[error("{0:?}")]
struct Generic<T: Debug>(T);
fn main() -> Result<(), Error<'static>> {
Err(Error(Inner("some text")))
}

View File

@ -1,5 +1,11 @@
error: non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static
--> $DIR/lifetime.rs:5:26
--> $DIR/lifetime.rs:6:26
|
5 | struct Error<'a>(#[from] Inner<'a>);
6 | struct Error<'a>(#[from] Inner<'a>);
| ^^^^^^^^^
error: non-static lifetimes are not allowed in the source of an error, because std::error::Error requires the source is dyn Error + 'static
--> $DIR/lifetime.rs:15:17
|
15 | Foo(#[from] Generic<&'a str>),
| ^^^^^^^^^^^^^^^^