Skip to content

Macro parser did not remove fragment correctly #19856

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

Open
A4-Tacks opened this issue May 24, 2025 · 1 comment
Open

Macro parser did not remove fragment correctly #19856

A4-Tacks opened this issue May 24, 2025 · 1 comment
Labels
A-macro macro expansion C-bug Category: bug

Comments

@A4-Tacks
Copy link
Contributor

rust-analyzer version: rust-analyzer 1.88.0-nightly (a15cce2 2025-04-17)

rustc version: rustc 1.88.0-nightly (a15cce269 2025-04-17)

editor or extension: VIM-9.1

code snippet to reproduce:

use proc_macro_impl::remove_fragment;

macro_rules! foo {
    (1+2) => {};
}
macro_rules! pack {
    ($e:expr) => {
        remove_fragment!(foo!($e))
    };
}

fn main() {
    pack!(1+2);
}
use proc_macro::*;
#[proc_macro]
pub fn remove_fragment(stream: TokenStream) -> TokenStream {
    stream.into_iter().map(|tt| {
        match tt {
            TokenTree::Group(g) => {
                let mut out = Group::new(g.delimiter(), remove_fragment(g.stream()));
                out.set_span(g.span());
                out.into()
            }
            _ => tt,
        }
    }).collect()
}

cargo build 0 errors

rust-analyzer.expandMacro:

// Recursive expansion of pack!! macro
// ====================================

Expansion had errors:
expected literal: `1`
@A4-Tacks A4-Tacks added the C-bug Category: bug label May 24, 2025
@ChayimFriedman2
Copy link
Contributor

That's invisible groups striking again (we don't handle them correctly).

@ChayimFriedman2 ChayimFriedman2 added the A-macro macro expansion label May 24, 2025
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
Projects
None yet
Development

No branches or pull requests

2 participants