rust-lang / rust-lang/rust-analyzer
Error expanding macro recursively at caret: `$crate` cannot come from `SyntaxContextId::ROOT`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
When trying to expand a proc_macro, most often the rust-analyzer errs with:
What's odd is that it doesn't always happen. Sometimes I can rebuild dependencies in our workspace, restart the LSP server, and it'll work. I also don't use $crate myself, though #[tokio::test], assert_eq!(), and some other macros may that end up getting expanded recursively.
This most often happens when I make a change to my crate e.g., minor bug fix or small behavior change as I tweak what it does for this in-development feature, and then try to expand the macro. rust-analyzer is rebuilding dependencies, but I've suspected it's a cached build output issue somehow.
rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
0.3.2212-standalone
rustc version: (eg. output of rustc -V)
rustc 1.80.0 (051478957 2024-07-21) (pinned via rust-toolchain.toml)
editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
VSCode rust-lang.rust-analyzer extension version v0.3.2212
relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)
Only a few relative things come to mind:
rust-toolchain.tomlpins channel to1.80.0.vscode/settings.jsonsets"rust-analyzer.cargo.features": "all"and"rust-analyzer.check.command": "clippy".
repository link (if public, optional): (eg. rust-analyzer)
- proc_macro: https://github.com/heaths/azure-sdk-for-rust/blob/09c9a45b1a267f304d34a55567e2935633f60cbe/sdk/core/azure_core_test_macros/src/test.rs
- use case: https://github.com/heaths/azure-sdk-for-rust/blob/09c9a45b1a267f304d34a55567e2935633f60cbe/sdk/cosmos/azure_data_cosmos/tests/cosmos_containers.rs#L19
code snippet to reproduce:
See links directly above.
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
Start with the proc_macro at sdk/core/azure_core_test_macros/src/test.rs and its use in sdk/cosmos/azure_data_cosmos/tests/cosmos_containers.rs#L19, using the pinned rust-toolchain.toml and the reported VSCode settings. Reproduce the recursive expansion failure after a dependency rebuild, then trace the relevant rust-analyzer macro-expansion path. Done means the failure has a reliable reproduction and its behavior is covered by a verified fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100