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

r-a shows leftover tokens error on fine code #11729

Closed
WaffleLapkin opened this issue Mar 16, 2022 · 0 comments · Fixed by #13800
Closed

r-a shows leftover tokens error on fine code #11729

WaffleLapkin opened this issue Mar 16, 2022 · 0 comments · Fixed by #13800
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@WaffleLapkin
Copy link
Member

rust-analyzer version: 5e85158 2022-03-14 nightly
rustc version: rustc 1.61.0-nightly (4ce374923 2022-02-28)

Given the following code:

#[macro_export]
macro_rules! when {
    (
        $(
            $(let $pat:pat = )? $cond:expr => $branch:expr
        ),+
        $(, _ => $def_branch:expr)?
        $(,)?
    ) => {
        $(
            if $(let $pat = )? $cond {
                $branch
            } else
        )+
        {
            $(
                $def_branch
            )?
        }
    };
}

#[test]
fn pattern() {
    let r = when! {
        let Some(x) = None => x,
        let Some(y) = Some(12) => y + 1,
        _ => 0,
    };

    assert_eq!(r, 13);
}

#[test]
fn mixed() {
    let r = when! {
        false => 0,
        let Some(_) = None::<bool> => 0,
        let Some(y) = Some(12) => y + 1,
        true => 1,
        _ => 0,
    };

    assert_eq!(r, 13);
}

r-a highlights both macro invocations saying "leftover tokens rust-analyzer(macro-error)" even though cargo test works fine ie compiler doesn't think that there are leftover tokens.

@bjorn3 bjorn3 added the A-macro macro expansion label Mar 16, 2022
@flodiebold flodiebold added the C-bug Category: bug label Mar 16, 2022
@jonas-schievink jonas-schievink added the S-actionable Someone could pick this issue up and work on it right now label Mar 28, 2022
@bors bors closed this as completed in ccbf8fe Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants