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

Unable to pass a $:literal from one macro to another #52169

Closed
dtolnay opened this issue Jul 9, 2018 · 2 comments
Closed

Unable to pass a $:literal from one macro to another #52169

dtolnay opened this issue Jul 9, 2018 · 2 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 9, 2018

I would expect the following program to print right. Instead it prints wrong.

#![feature(macro_literal_matcher)]

macro_rules! a {
    ($i:literal) => { "right" };
    ($i:tt) => { "wrong" };
}

macro_rules! b {
    ($i:literal) => { a!($i) };
}

fn main() {
    println!(b!(0));
}

Originally reported by @jendrikw in #35625 (comment).

@dtolnay dtolnay added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. labels Jul 9, 2018
@0e4ef622
Copy link
Contributor

0e4ef622 commented Aug 5, 2018

Is any work being done on this? I found something that could help.

syntax::ext::tt::macro_parser: may_begin_with("literal", Interpolated((NtLiteral(..), None))) = false

@kennytm
Copy link
Member

kennytm commented Aug 5, 2018

@0e4ef622 you're welcome to submit a PR 😊. Just remember to add a test case in src/test/run-pass.

kennytm added a commit to kennytm/rust that referenced this issue Aug 7, 2018
…enkov

Enable macros to pass $:literal to another macro

Fixes rust-lang#52169.
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.
Projects
None yet
Development

No branches or pull requests

3 participants