frozenlib / parse-display

Procedural macro to implement Display and FromStr using common settings.
Apache License 2.0
182 stars 14 forks source link

Use result with full path in the generated code #26

Closed irevoire closed 1 year ago

irevoire commented 1 year ago

Hello, I tried to learn parse-display today while playing with the advent of code and it wasn’t working with a strange error;

error[E0308]: mismatched types
   --> day2/src/bin/part2.rs:71:10
    |
71  | #[derive(FromStr, PartialEq, Debug, Clone, Copy)]
    |          ^^^^^^^
    |          |
    |          expected struct `ParseError`, found struct `aoc::Error`
    |          expected `Result<Match, ParseError>` because of return type
    |          in this derive macro expansion
    |
   ::: /Users/irevoire/.cargo/registry/src/github.com-1ecc6299db9ec823/parse-display-derive-0.6.0/src/lib.rs:151:1
    |
151 | pub fn derive_from_str(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    | --------------------------------------------------------------------------------- in this expansion of `#[derive(FromStr)]`
    |
    = note: expected enum `Result<_, ParseError>`
               found enum `Result<_, aoc::Error>`

To me it look like the issues comes down to the fact that I re-exported a custom Result type, but actually no, when I do it explicitly I have no issue.

I don’t really know what generate this error but with this PR it’s fixed.

If you want to understand it better to be able to write a test here is how to reproduce it:

git clone https://github.com/irevoire/aoc2022.git
cd aoc2022/day2
sd 'use aoc::.*$' 'use aoc::*;' **/*.rs
cargo run --bin part2 smol
frozenlib commented 1 year ago

Looks good thanks!