Registry Mirror
Skip to content

Macro lifetimes aren't a thing (yet) #268

Closed

Description

@Phlosioneer

The return value of one of my named! parsers has a lifetime parameter. I need to make the function take a lifetime parameter. Does nom currently support this?

My situation:

pub enum Expression<'a> {
  String(&'a str)
  // other stuff...
}

named!(pub string_parser<Expression<'a> >,
  // other stuff...
  );

Cargo gives:


src/expressions.rs:15:22: 15:24 error: use of undeclared lifetime name `'a` [E0261]
src/expressions.rs:15 named!(pub string_parser<&'a str>, 
                                                ^~
src/expressions.rs:15:1: 19:5 note: in this expansion of named! (defined in <nom macros>)
src/expressions.rs:15:22: 15:24 help: run `rustc --explain E0261` to see a detailed explanation

The expanded macro definition:

pub fn string_parser(i: &[u8]) -> ::nom::IResult<&[u8], Expression<'a>, u32> {

'a is equal to the lifetime of the data being parsed, if that helps. Rust was able to infer that when it wasn't public, but as public it can't make that assumption.

Activity

  1. Phlosioneer commented on Jun 21, 2016

    @Phlosioneer
    ContributorAuthor

    Turns out this is an issue in rust: rust-lang/rust#27832

  2. changed the title [-]How to use lifetimes?[/-] [+]Macro lifetimes aren't a thing (yet)[/+] on Jun 21, 2016
  3. Phlosioneer commented on Jun 21, 2016

    @Phlosioneer
    ContributorAuthor

    Just a few days ago, this issue was fixed in the RFC rust-lang/rfcs#1590. The PR against rustc is coming soon. So it'll be in nightly soonish. At that point, I'll probably do a personal fork of nom to add the nightly feature, unless there's a way for nom to handle nightly.

    Closing because this isn't an issue anymore.

  4. Geal commented on Jun 21, 2016

    @Geal
    Collaborator

    you could at least leave me some time to answer before closing ;)

    named! is just a helper, you can always write your own function definition. I probably wouldn't add something that only appears in nightly, or at least I would hide it behind a feature flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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