derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

ParseError when implement Display derive for enum

Open qhliang opened this issue 2 years ago • 2 comments

Awesome library, i like it!

I found some small problems during use, in some cases, it will be panic. The following is an example:

#[derive(Display)]
#[display(fmt = "{_0}")]
enum NodeType {
    Base(&'static str),
    Main(&'static str),
    N1(&'static str),
    N2(&'static str),
    N3(&'static str),
    N4(&'static str),
}

Here is the compile error result:

error: proc-macro derive panicked
  --> src/main.rs:93:10
   |
93 | #[derive(Display)]
   |          ^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: ParseError { line: 1, column: 2, offset: 1, expected: {"}", "[0-9]", ":"} }

I can't find the cause of the problem from the message.

qhliang avatar Feb 09 '23 10:02 qhliang

@ilslv I guess this is not the case anymore on latest master, but maybe you could add tests covering that, just to be sure?

tyranron avatar Feb 09 '23 18:02 tyranron

@tyranron actually this case doesn't work on master, but for a different reason: we haven't decided yet on how to implement affix https://github.com/JelteF/derive_more/issues/142

ilslv avatar Feb 10 '23 06:02 ilslv