Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.8 broke my error() derive #53

Closed
jyn514 opened this issue Dec 4, 2019 · 3 comments
Closed

1.0.8 broke my error() derive #53

jyn514 opened this issue Dec 4, 2019 · 3 comments

Comments

@jyn514
Copy link

jyn514 commented Dec 4, 2019

I just upgraded from 1.0.4 to 1.0.8 and it broke my build. The following used to compile fine with thiserror:

use thiserror::Error;

#[derive(Debug)]
struct Inner {
    data: String
}

#[derive(Debug, Error)]
#[error("{}", .0.data)]
struct S(Inner);

fn main() {
    let s = S(Inner { data: "Hello, world!".to_string() });
    println!("{}", s);
}

With 1.0.8, I now get an error:

error[E0277]: `Inner` doesn't implement `std::fmt::Display`
 --> src/main.rs:9:16
  |
9 | #[error("{}", .0.data)]
  |                ^ `Inner` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for `Inner`
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
  = note: required by `std::fmt::Display::fmt`

error: aborting due to previous error

Is this intentional? If so, why? I don't need to print .0 to print the error message.

Some more things I tried:

  • #[error("{}", 0.data)]
error[E0308]: mismatched types
 --> src/main.rs:9:15
  |
9 | #[error("{}", 0.data)]
  |               ^
  |               |
  |               expected reference, found integer
  |               help: consider borrowing here: `&0`
  • #[error("{}", &0.data)]
error: expected expression, found `,`
 --> src/main.rs:8:17
  |
8 | #[derive(Debug, Error)]
  |                 ^^^^^ expected expression

error: proc-macro derive produced unparseable tokens
 --> src/main.rs:8:17
  |
8 | #[derive(Debug, Error)]
  |                 ^^^^^
  • #[error("{}", (.0).data)]: expected reference, found struct 'std::string::String'
  • #[error("{}", (&.0.data))] - error: float literals must have an integer part
  • #[error("{}", (&self.0.data))] - works but gives warning about unneccessary parentheses
  • #[error("{}", &self.0.data)] - error: proc-macro derive produced unparseable tokens
@jyn514
Copy link
Author

jyn514 commented Dec 4, 2019

Just bisected locally and this first broke in 1.0.7, 1.0.6 works fine.

jyn514 added a commit to jyn514/saltwater that referenced this issue Dec 4, 2019
lock in a lower version of `thiserror` until
dtolnay/thiserror#53 is fixed
@dtolnay dtolnay closed this as completed in 20202db Dec 4, 2019
@dtolnay
Copy link
Owner

dtolnay commented Dec 4, 2019

Sorry about the breakage! This was a bug in one of the changes in 1.0.7. I released 1.0.9 with a fix.

@jyn514
Copy link
Author

jyn514 commented Dec 4, 2019

1.0.9 works great! Thanks so much for the quick fix :)

jyn514 added a commit to jyn514/saltwater that referenced this issue Dec 4, 2019
thanks again to dtolnay for the quick fix :)

See dtolnay/thiserror#53 for context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants