shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.45k stars 61 forks source link

Unhygienic Display impl #202

Closed pie-flavor closed 4 years ago

pie-flavor commented 4 years ago

Given this code:

use snafu::Snafu;

#[derive(Debug, Snafu)]
pub enum Error {
    #[snafu(display("{}", f))]
    Whatever {
        f: i32,
    }
}

cargo build produces:

error[E0599]: no method named `write_fmt` found for type `&i32` in the current scope

which is caused by the name f conflicting with the name of the &mut Formatter in the Display impl.

shepmaster commented 4 years ago

Yuck. Thank you for the report! I'm going to see if there's some nice solution to prevent that for good. Otherwise, I'll rename it to something really hard collide with and push up a patch version soon-ish.

Out of my own morbid curiosity, why do you have a field called f?

pie-flavor commented 4 years ago

@shepmaster It was short for file.

shepmaster commented 4 years ago

Should be fixed on 0.6.1, thanks again for the report!