kevinmehall / rust-peg

Parsing Expression Grammar (PEG) parser generator for Rust
https://crates.io/crates/peg
MIT License
1.46k stars 106 forks source link

Box<impl Trait> `peg` 0.8.1 regression #319

Closed fmorency closed 2 years ago

fmorency commented 2 years ago

Compilation of a peg::parser containing a function returning a Box<impl Trait> will fail with peg 0.8.1 but succeed with peg 0.8.0.

E.g.

peg::parser!{
        grammar list_parser() for str {
            rule number() -> u64
                = n:$(['0'..='9']+) {? n.parse().or(Err("u64")) }

            pub rule list() -> Box<impl FooTrait>
                = n:(number()) { Box::new(FooStruct { val: n }) }
        }
    }

MRE: https://github.com/fmorency/peg-box-impl

kevinmehall commented 2 years ago

Oops, this is from adding a type annotation to help type inference (https://github.com/kevinmehall/rust-peg/pull/317), but impl Trait can't be named except in a return type position. We'll have to figure out how to fix type inference in that case without explicitly naming the type.