rust-bakery / nom

Rust parser combinator framework
MIT License
9.18k stars 792 forks source link

nom 5->nom 7, opt parser lifetime problem #1667

Open hce opened 1 year ago

hce commented 1 year ago

Hello, this is not really an issue with nom per se but I am confused and don't know where else to turn to. I just bumped the nom version in my project from 5 to 7 and got a few compiler errors with my code that compiled fine before. The code always goes like this:

    let (input, some_value) = opt(|input: &str| {
        [...]
        Ok(input, value)
    })(input)?;

Worked fine with nom 5, fails with nom 7 with the following error:

returning this value requires that `'1` must outlive `'2`

What's stranger still, just by change I discovered I can "fix" the problem by removing the type annotation in the lambda function and writing instead:

    let (input, some_value) = opt(|input| {
        let input: &str = input;
        [...]
        Ok(input, value)
    })(input)?;

Could you help me understand a) what is causing this error in nom 7 and not nom 5 (both compiled with rustc 1.69.0 (84c898d65 2023-04-16)) and b) why my weird "fix" is working?

Thanks a lot in advance! :-)

Geal commented 1 year ago

no idea, maybe that is caused by the move to returning a FnMut :thinking: