failure_derive icon indicating copy to clipboard operation
failure_derive copied to clipboard

allow accessing attributes and methods in #[fail(display=)] string interpolation

Open radix opened this issue 8 years ago • 2 comments

In error-chain, I had stuff like:

    ItemAlreadyExists(iid: ItemID) {
      description("An Item already exists.")
      display("The Item {} already exists", iid.0)
    }

but it appears that accessing attributes like this is illegal in failure_derive:

    #[fail(display="The Item {} already exists", _0.0)]
    ItemAlreadyExists(ItemID),

leads to

error: expected one of `(`, `,`, or `=`, found `.`
   --> pandt\src\types.rs:747:52
    |
747 |     #[fail(display="The Item {} already exists", _0.0)]
    |                                                    ^ expected one of `(`, `,`, or `=` here

radix avatar Nov 21 '17 00:11 radix

actually, I made a mistake, that's not the right error. I'm just getting a general "Failed to parse input" error, but I haven't figured out if this is exactly what's causing the parsing error...

radix avatar Nov 21 '17 00:11 radix

This is an unfortunate limitation of the rustc attribute syntax; once attributes are more flexible, I intend to make this work more like how you would expect it to (self.0 instead of _0, support methods and so on).

I was working on a PR to make rustc accept more syntax here, but I dropped the ball on it: https://github.com/rust-lang/rust/pull/45244

withoutboats avatar Nov 27 '17 23:11 withoutboats