Skip to content

Merge InputLength into Input can introduce extra trait requirement #1809

@tisonkun

Description

@tisonkun

See andylokandy/nom-rule#8

Previously, we have:

nom/src/multi/mod.rs

Lines 52 to 58 in 869f897

#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
pub fn many0<I, O, E, F>(mut f: F) -> impl FnMut(I) -> IResult<I, Vec<O>, E>
where
I: Clone + InputLength,
F: Parser<I, O, E>,
E: ParseError<I>,
{

and

pub trait InputLength {
  fn input_len(&self) -> usize;
}

impl<'a, T> InputLength for &'a [T] {
  #[inline]
  fn input_len(&self) -> usize {
    self.len()
  }
}

So InputLength is implemented for &[proc_macro2::TokenTree].

But now we have:

nom/src/multi/mod.rs

Lines 61 to 67 in 2cec1b3

#[cfg(feature = "alloc")]
#[cfg_attr(feature = "docsrs", doc(cfg(feature = "alloc")))]
pub fn many0<I, F>(
f: F,
) -> impl Parser<I, Output = Vec<<F as Parser<I>>::Output>, Error = <F as Parser<I>>::Error>
where
I: Clone + Input,

So &[proc_macro2::TokenTree] can no longer directly adapted in many0.

Perhaps we can wrap a newtype to work it around. But I'd first report this use case and see if there is better/idiomatic way.

cc @Geal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions