Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.
/ paste Public archive
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

Parser error with :lifetime param in expanded code #26

@danielhenrymantilla

Description

@danielhenrymantilla

Minimal repro:

macro_rules! m {(
    $lt:lifetime
) => (
    ::paste::item! {
        impl<$lt> () {}
    }
)}

m! { 'lt }

leads to a parser error saying that:

  • 1.45.0-nightly (90931d9b3 2020-04-28)

    error: lifetime in trait object type must be followed by `+`
    
  • 1.43.0 (3532cf738 2020-03-17)

    error: expected type, found `'lt`
    
  • A run with cargo bisect seems to indicate this bug has always been present.


EDIT: After some testing, here is a minimal proc-macro repro (that is, if we replace ::paste::item! by foo!, the same parsing error is triggered):

#[proc_macro] pub
fn foo (it: TokenStream) -> TokenStream
{
    it  .into_iter()
        .map(|tt| tt) // without this line, there is no error (I imagine due to some specialization) 
        .collect::<TokenStream>()
      //.to_string().parse().unwrap() /* workaround! */
}

This minimal repro suggests that this is not really an issue with paste, but with some proc-macro :lifetime capture interaction... Since you know the internals of a TokenStream better, @dtolnay, I'll let you investigate it further and post an appropriate issue on rust-lang/rust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions