-
-
Save tjkirch/8917dd863bc284db20384fb303651ea6 to your computer and use it in GitHub Desktop.
Minimal example of compile eerror with recursive Snafu errors, for snafu#59 comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use snafu::{ResultExt, Snafu}; | |
#[derive(Debug, Snafu)] | |
enum Error { | |
#[snafu(display("Plain error"))] | |
Plain {}, | |
#[snafu(display("Recursive variant: {}", source))] | |
// #[snafu(source(from(Error, Box::new)))] | |
#[snafu(source(from(Error, |e| Box::new(e))))] | |
Recursive { source: Box<Error> }, | |
} | |
fn main() -> Result<(), Error> { | |
Plain {} | |
.fail() | |
//.map_err(Box::new) | |
// Without the map_err above, you get the following error, regardless which of the two | |
// "source(from)" invocations you use above. | |
// | |
// error[E0271]: type mismatch resolving `<Recursive as snafu::IntoError<Error>>::Source == Error` | |
// --> src/main.rs:22:10 | |
// | | |
// 22 | .context(Recursive {}) | |
// | ^^^^^^^ expected struct `std::boxed::Box`, found enum `Error` | |
// | | |
// = note: expected type `std::boxed::Box<Error>` | |
// found type `Error` | |
.context(Recursive {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment