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

Panic when using dotted access syntax in attributes (regression from 0.18 to 0.19.1) #104

Closed
Veetaha opened this issue Aug 5, 2020 · 4 comments

Comments

@Veetaha
Copy link

Veetaha commented Aug 5, 2020

The new 0.19.1 version of strum_macros panics when reaches the dot operator expression in attributes metadata which might be used by snafu macros for example (see reproduction in the end).

The error message is so unhelpful that to understand where the bug comes from one needs clone this repo
and do a binary search with synthetically inserting panic!("Here") in code here and there.

The error message
error: proc-macro derive panicked
  --> crates/foo/src/main.rs:10:10
   |
10 | #[derive(IntoStaticStr)]
   |          ^^^^^^^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: Error("expected `,`")

At the end of the day the panic comes from syn on this line of code:

.map(|attr| attr.parse_meta().unwrap())

Change that unwrap() to expect("Boom") to check that this really is the place of panic.

Reproduction (panics on 0.19.1 of strum_macros, but version 0.18.0 works fine):

use snafu::Snafu; // "0.6.8"
use strum_macros::IntoStaticStr;

#[derive(Debug)]
struct Inner {
    foo: &'static str
}

#[derive(Debug, Snafu)]
#[derive(IntoStaticStr)] // if you comment out this line, the crate compiles well
enum Error {
    #[snafu(display("Inner: {}", inner.foo))] // inner.foo syntax causes the panic (probably the dot)
    A {
        inner: Inner
    }
}

fn main() {
    dbg!(Error::A { inner: Inner { foo: "bar" } });
}

cc #100

@Peternator7
Copy link
Owner

Should be fixed by #105. Can you verify locally?

@Veetaha
Copy link
Author

Veetaha commented Aug 6, 2020

Yup, with #105 there is no panic

@Peternator7
Copy link
Owner

PR is merged, and crate is published. 0.19.2 should fix this issue.

@Veetaha
Copy link
Author

Veetaha commented Aug 6, 2020

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants