Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Phlosioneer opened this issue Jun 21, 2016 · 3 comments
Closed

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

Phlosioneer opened this issue Jun 21, 2016 · 3 comments

Comments

@Phlosioneer
Copy link
Contributor

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.

@Phlosioneer
Copy link
Contributor Author

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

@Phlosioneer Phlosioneer changed the title How to use lifetimes? Macro lifetimes aren't a thing (yet) Jun 21, 2016
@Phlosioneer
Copy link
Contributor Author

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.

@Geal
Copy link
Collaborator

Geal commented Jun 21, 2016

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants