rust-lang / rust-lang/rust-analyzer
Missing `None` delimited group when expanding decl macros expanding to proc macros
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the minimal three-crate example from the issue, comparing cargo build --example simple with rust-analyzer's proc-macro expansion. Start by tracing how decl macros are evaluated before invoking bunt_macros::bar; the fix is complete when both paths pass the same token stream without the spurious None-delimited group or diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100