snafu icon indicating copy to clipboard operation
snafu copied to clipboard

Cannot use lifetime-parameterized errors as sources

Open shepmaster opened this issue 5 years ago • 2 comments

Code like this won’t work:

#[derive(Debug, Snafu)]
enum Error<T> {
    Generic { source: GenericError<‘a, T> },
}

We need a reference with the ’static bound to be able to call Error::source.

We could perhaps disable the ability to call Error::source by just returning None.

shepmaster avatar Jun 29 '19 15:06 shepmaster

Could not Snafu also conditionally supports error types as:

#derive(Debug, Snafu)
enum Error<T> {
     Foo{ source: T}
}

I suppose it could be done by detecting that a source depend on a generic parameter and then, for each struct/trait generated by snafu add a WherePredicate T: 'static + Error

Kannen avatar Jun 28 '21 08:06 Kannen

That certainly seems like an avenue worth pursuing! Sometimes the compiler errors arising from conditional implementations are hard to decipher though.

shepmaster avatar Jul 02 '21 19:07 shepmaster