Skip to content

Missing None delimited group when expanding decl macros expanding to proc macros #7787

@LukasKalbertodt

Description

@LukasKalbertodt

Minimal example

There are three crates: bunt-macros (exporting proc macro), bunt (exporting decl macro) and the simple example. Excuse the naming, but this issue popped up here. You can see the whole example on this branch.

lib.rs of bunt-macros

use proc_macro::TokenStream;

#[proc_macro]
pub fn bar(input: TokenStream) -> TokenStream {
    panic!("{:#?}", input);
}

lib.rs of bunt:

pub extern crate bunt_macros;

#[macro_export]
macro_rules! foo {
    ($target:expr) => {
        $crate::bunt_macros::bar!($target)
    };
}

simple.rs

fn main() {
    bunt::foo!(peter);
}

If you cargo build --example simple, you get this output:

error: proc macro panicked
 --> examples/simple.rs:3:5
  |
3 |     bunt::foo!(peter);
  |     ^^^^^^^^^^^^^^^^^^
  |
  = help: message: TokenStream [
    Group {
        delimiter: None,
        stream: TokenStream [
            Ident {
                ident: "peter",
                span: #0 bytes(28..33),
            },
        ],
        span: #6 bytes(8793927..8793934),
    },
]

However, if I just save simple.rs in VScode with RA proc macro expansion activated, it shows this error (when hovering over the macro call):

proc macro returned error: proc-macro panicked: TokenStream [
    Ident {
        ident: "peter",
        span: 4294967295,
    },
] rust-analyzermacro-error

RA seems to not add this "dummy group" when evaluating the decl macro. This minimal example just shows how RA does things differently than rustc and this can obviously lead to errors where RA shows an error where rustc compiles fine.

This Rust PR might be related.

Meta

RA: 2021-02-22 (14de9e5)
Rust: rustc 1.50.0 (cb75ad5db 2021-02-10)

If I can provide any more information, please let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions