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

Regression in procedural macros emitting macro_rules macros #39889

Closed
dtolnay opened this issue Feb 16, 2017 · 1 comment · Fixed by #39419
Closed

Regression in procedural macros emitting macro_rules macros #39889

dtolnay opened this issue Feb 16, 2017 · 1 comment · Fixed by #39419
Assignees
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 16, 2017

my-macro/src/lib.rs

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(Useless)]
pub fn demo(_input: TokenStream) -> TokenStream {
    let rules = r#"
        macro_rules! id {
            ($($tt:tt)*) => { $($tt)* };
        }
    "#;
    rules.parse().unwrap()
}

testing/src/main.rs

#[macro_use]
extern crate my_macro;

#[derive(Useless)]
struct _S;

pub fn main() {
    println!("{}", id!(true));
}

rustup run nightly-2017-02-13 cargo run

true

rustup run nightly-2017-02-16 cargo run

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> src/main.rs:4:10
  |
4 | #[derive(Useless)]
  |          ^^^^^^^

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> src/main.rs:4:10
  |
4 | #[derive(Useless)]
  |          ^^^^^^^

error: aborting due to 2 previous errors

cc @jseyfried who touched macro expansion recently

@jseyfried
Copy link
Contributor

@dtolnay Sorry for the delay! This will get fixed by #39419 (added a regression test).

frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 1, 2017
Simplify `TokenTree` and fix `macro_rules!` bugs

This PR
 - fixes rust-lang#39390, fixes rust-lang#39403, and fixes rust-lang#39404 (each is a [breaking-change], see issues for examples),
 - fixes rust-lang#39889,
 - simplifies and optimizes macro invocation parsing,
 - cleans up `ext::tt::transcribe`,
 - removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`,
   - instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`)
 - removes `parser.quote_depth` and `parser.parsing_token_tree`, and
 - removes `quote_matcher!`.
   - Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`.
   - I found no outside uses of `quote_matcher!` when searching Rust code on Github.

r? @nrc
bors added a commit that referenced this issue Mar 1, 2017
Simplify `TokenTree` and fix `macro_rules!` bugs

This PR
 - fixes #39390, fixes #39403, and fixes #39404 (each is a [breaking-change], see issues for examples),
 - fixes #39889,
 - simplifies and optimizes macro invocation parsing,
 - cleans up `ext::tt::transcribe`,
 - removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`,
   - instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`)
 - removes `parser.quote_depth` and `parser.parsing_token_tree`, and
 - removes `quote_matcher!`.
   - Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`.
   - I found no outside uses of `quote_matcher!` when searching Rust code on Github.

r? @nrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants