Skip to content

Macro parser did not remove fragment correctly #19856

@A4-Tacks

Description

@A4-Tacks

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions