This is on Snafu 0.8.9, default features, on rust 1.90.0.
When creating a snafu error enum that uses a whatever-based return, the code fails to compile. Below is an example where this fails:
use snafu::{whatever, ResultExt, Snafu};
#[derive(Debug, Snafu)]
enum MyError {
#[snafu(transparent)]
SomeTransparentError { source: std::io::Error },
#[snafu(whatever, display("{message}"))]
SomeWhateverError {
message: String,
#[snafu(source(from(Box<dyn std::error::Error>, Some)))]
source: Option<Box<dyn std::error::Error>>,
},
}
fn broken_fn() -> Result<(), MyError> {
inner_fn().whatever_context("some context")?;
Ok(())
}
fn working_fn() -> Result<(), MyError> {
inner_fn().whatever_context("some context")
}
fn inner_fn() -> Result<(), MyError> {
whatever!("die");
}
The broken_fn() fails to compile with the following error:
error[E0284]: type annotations needed
--> scheduler/src/buggy.rs:17:16
|
17 | inner_fn().whatever_context("some context")?;
| ^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `E2` declared on the method `whatever_context`
|
= note: cannot satisfy `<_ as FromString>::Source == _`
help: consider specifying the generic arguments
|
17 | inner_fn().whatever_context::<&str, E2>("some context")?;
| ++++++++++++
If you remove the #[snafu(transparent)] annotation, this compiles perfectly. You can have as many variants as you want, and it doesn't seem to matter what the transparent error actually is.
This is on Snafu 0.8.9, default features, on rust 1.90.0.
When creating a snafu error enum that uses a whatever-based return, the code fails to compile. Below is an example where this fails:
The broken_fn() fails to compile with the following error:
If you remove the
#[snafu(transparent)]annotation, this compiles perfectly. You can have as many variants as you want, and it doesn't seem to matter what the transparent error actually is.