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

Nested macro_rules with $$ fails to expand #12364

Closed
TimNN opened this issue May 23, 2022 · 2 comments
Closed

Nested macro_rules with $$ fails to expand #12364

TimNN opened this issue May 23, 2022 · 2 comments

Comments

@TimNN
Copy link
Contributor

TimNN commented May 23, 2022

rust-analyzer version: Current HEAD (7be85a5)

rustc version: rustc 1.61.0 (fe5b13d68 2022-05-18) and rustc 1.63.0-nightly (b2eed72a6 2022-05-22)

Rust Analyzer fails to expand the following code (playground):

#![feature(macro_metavar_expr)]

macro_rules! outer {
    ($outer_name:ident) => {
        macro_rules! inner {
            ($$inner_name:ident) => {
                impl $outer_name {
                    fn $$inner_name() {}
                }
            };
        }
    };
}

struct Hello;

outer!(Hello);
inner!(world);

Replacing the $$ with singular $s fixes the issues (though note that there are macros where the $$ is necessary). $$ is close to being stabilized: rust-lang/rust#95860

I've added a test case in TimNN@856d689, which produces the following results:

$ cargo test -p hir-def nested_double_dollar
    Finished test [unoptimized] target(s) in 0.09s
     Running unittests src/lib.rs (target/debug/deps/hir_def-96fd50c42b79c470)

running 1 test
test macro_expansion_tests::mbe::nested_double_dollar ... FAILED

failures:

---- macro_expansion_tests::mbe::nested_double_dollar stdout ----
thread 'macro_expansion_tests::mbe::nested_double_dollar' panicked at 'called `Result::unwrap()` on an `Err` value: UnresolvedMacro { path: ModPath { kind: Plain, segments: [Name(Text("inner"))] } }', crates/hir-def/src/macro_expansion_tests/mbe.rs:1550:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    macro_expansion_tests::mbe::nested_double_dollar

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 331 filtered out; finished in 0.00s

Again, replacing the $$ with $ makes the test pass.

@Veykril
Copy link
Member

Veykril commented May 23, 2022

We don't support macro_metvar_expr yet, #11952

@Veykril Veykril closed this as completed May 23, 2022
@TimNN
Copy link
Contributor Author

TimNN commented May 24, 2022

Ah, thanks for linking the issue! (Didn’t find anything when I was searching for something like “nested macros”, IIRC).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants