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

Erroneous expression parsing of macro invocations with paths #44065

Closed
SergioBenitez opened this issue Aug 23, 2017 · 4 comments
Closed

Erroneous expression parsing of macro invocations with paths #44065

SergioBenitez opened this issue Aug 23, 2017 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SergioBenitez
Copy link
Contributor

Consider the following rustc internal code which parses an ast::Path and returns an invocation of a macro at that path:

let mut parser = ecx.new_parser_from_tts(args);
let path = parser.parse_path(PathStyle::Mod).expect("path");
MacEager::expr(quote_expr!(ecx, $path!()))

The expected expansion of a procedural macro implemented in this manner is PATH ! ( ). Instead, this expands to PATH erroneously. Said another way, if the code above corresponded to a macro named m, we would expect m!(some_path); to expand to some_path!() when it instead expands to some_path.

Note that if instead an ast::Ident is used in place of the ast::Path above, things work as expected. This corresponds to the code below:

let mut parser = ecx.new_parser_from_tts(args);
let ident = parser.parse_ident().expect("ident");
MacEager::expr(quote_expr!(ecx, $ident!()))

After some investigation, the issue appears to reside in Parser::parse_expr. I've created a repository where the issue can be reproduced: https://github.com/SergioBenitez/path-macro-repro. The repository also includes a work around for the problem (https://github.com/SergioBenitez/path-macro-repro/blob/master/src/lib.rs#L27).

@SergioBenitez SergioBenitez changed the title Erroneous expression parsing of macro invocations with path Erroneous expression parsing of macro invocations with paths Aug 23, 2017
@SergioBenitez
Copy link
Contributor Author

Likely related to #36662.

@nrc
Copy link
Member

nrc commented Aug 23, 2017

Is there any way to observe this without using compiler internals (i.e., macros 1.0 proc macros)?

@SergioBenitez
Copy link
Contributor Author

@nrc Falling back to a TokenStream, converting that into a String, and parsing as an expression works as expected. Since this is pretty close to what would happen in a proc-macros 2.0 implementation, I would say that it's unlikely this can be seen outside of the compiler internals or proc-macros 1.0.

@shepmaster shepmaster added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 25, 2017
@Enselic
Copy link
Member

Enselic commented Sep 15, 2023

Triage: Closing since

  • The reproducer repo is gone
  • This can't be observed by regular users, only when using compiler internals

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2023
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, ..) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants