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

Allow lifetimes in macros #41927

Closed
wants to merge 2 commits into from
Closed

Conversation

mikeyhew
Copy link
Contributor

@mikeyhew mikeyhew commented May 11, 2017

This is a resurrection of PR #33135.

@sgrif can you take a look at the following diffs from #33135, and see if those changes are still necessary?

Still to do:

  • Make sure CI passes
  • Get approval from @sgrif, since he wrote the code
  • Feature gate

mikeyhew added 2 commits May 10, 2017 01:04
Started rebasing @sgrif's PR rust-lang#33135 off of current master. (Well, actually merging it into a new branch based off current master.)

The following files still need to be fixed or at least reviewed:

- `src/libsyntax/ext/tt/macro_parser.rs`: calls `Parser::parse_lifetime`, which doesn't exist anymore
- `src/libsyntax/parse/parser.rs`: @sgrif added an error message to `Parser::parse_lifetime`. Code has since been refactored, so I just took it out for now.
- `src/libsyntax/ext/tt/transcribe.rs`: This code has been refactored bigtime. Not sure whether @sgrif's changes here are still necessary. Took it out for this commit.
made `parser::Parser::expect_lifetime` public, so it can be called from `macro_parser::parse_nt`
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2017
@shepmaster
Copy link
Member

Thanks @mikeyhew! We'll get @pnkfelix to take a look at this PR shortly!

@kennytm
Copy link
Member

kennytm commented May 12, 2017

All three tests failed, "expected one of >, identifier, or lifetime, found 'a".


BTW, could you add some tests to show that the patch handles labels?

#![allow(unreachable_code)]

macro_rules! x {
    ($a:lifetime) => {
        $a: loop {
            break $a;
            panic!("failed");
        }
    }
}
macro_rules! br {
    ($a:lifetime) => {
        break $a;
    }
}
macro_rules! br2 {
    ($b:lifetime) => {
        'b: loop {
            break $b; // this $b should refer to the outer loop.
        }
    }
}
fn main() {
    x!('a);
    'c: loop {
        br!('c);
        panic!("failed");
    }
    'b: loop {
        br2!('b);
        panic!("failed");
    }
}

@shepmaster shepmaster added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 12, 2017
@mikeyhew
Copy link
Contributor Author

Thanks @kennytm, and sure, I'll add those tests. What is the quickest way to run tests for libsyntax? Anything with --stage 1 seems to take forever to build.

@petrochenkov
Copy link
Contributor

@mikeyhew

Anything with --stage 1 seems to take forever to build.

Do you include LLVM build and similar in "forever"? It only needs to be done once.
"Development cycle" includes only build from modifying libsyntax to running stage 1 tests.
The only way to speed it up that I know is to set codegen-units = 0 in config.toml, with it time ../x.py test --stage 1 src/test/run-pass --test-args macroxxx gives real 4m14.233s. Slow, but not forever (I'm on a relatively fast desktop machine though).
You can also try to add --incremental to the x.py command line (I haven't measured time for it because it breaks the build on my machine.).

@bors
Copy link
Contributor

bors commented May 17, 2017

☔ The latest upstream changes (presumably #42049) made this pull request unmergeable. Please resolve the merge conflicts.

@mikeyhew
Copy link
Contributor Author

I'm too busy with school right now, and I still don't really understand the code in this PR so I'm going to give up. Someone else will have to take over for this to get implemented.

@mikeyhew mikeyhew closed this May 20, 2017
@ricochet1k ricochet1k mentioned this pull request Dec 20, 2017
1 task
bors added a commit that referenced this pull request Jan 1, 2018
Allow lifetimes in macros

This is a resurrection of PR #41927 which was a resurrection of #33135, which is intended to fix #34303.

In short, this allows macros_rules! to use :lifetime as a matcher to match 'lifetimes.

Still to do:
- [x]  Feature gate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants