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

macros: simplify tt matchers #39403

Closed
jseyfried opened this issue Jan 30, 2017 · 2 comments · Fixed by #39419
Closed

macros: simplify tt matchers #39403

jseyfried opened this issue Jan 30, 2017 · 2 comments · Fixed by #39419
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@jseyfried
Copy link
Contributor

jseyfried commented Jan 30, 2017

Ideally, tt matches either a single token or delimited sequence (e.g. { arbitrary tokens }).
However, the following compiles today:

macro_rules! m { ($t:tt) => {} }
m!($x);
m!($(x)*);
m!($x:ident);

We want to avoid leaking details of macro_rules! syntax into the semantics of tt, at least for macros 2.0.

@jseyfried jseyfried self-assigned this Jan 30, 2017
@jseyfried jseyfried added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jan 30, 2017
@durka
Copy link
Contributor

durka commented Jan 31, 2017

What does "fixing" this entail? Which examples still work?

@jseyfried
Copy link
Contributor Author

@durka
None of those examples will work with macros 2.0, but then macros 2.0 will allow escaping $.

I think fixing this means that at least the second and third examples don't work. However, we might need to continue allowing the first example for back-compat and since there isn't a good workaround without being able to escape $.

Also, we could enable escaping $ in macro_rules! and then forbid the first example.

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
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants