rust-lang / rust-lang/rust-analyzer
Inlay hints for 1-occurrence only macro_rules
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Minimization/specialization of #11323: Please show inlay hints for invocations of macro_rules!-based macros, where the active/applied rule/part of that macro_rules! uses/outputs the relevant captured macro $variable ONCE ONLY. (That is, the relevant capturing $variable is not used in any active/applied part's $(...)+ or $(...)*, and it's not used/printed twice or more in the active/applied branch of the macro_rules!.)
This may sound useless or too restrictive. BUT, macro designers can design a rust-analyzer-only feature that would have such dummy macros (selected by conditional compilation based on the feature's presence). That would be used with rust-analyzer only - not to be used for debug/production. (These dummy macros could be much simpler than the real debug/release macros, simplified by potentially using unreachable!() or unreachable!() as XXX to generate any missing/complex values. When under that feature, the crate can also conditionally import no-link crate to ensure that it can't be linked to.)
Then debug/production builds would use the real macro_rules! implementation (or have a macro_rules! shim that forwards to a (separate) proc macro crate instead, or just pub use re-export the proc macros from a (separate) proc macro crate). That doesn't need to have any inlays shown.
(For proc macros that would mean addition of another, non-proc macro, crate, which either forwards the requests or re-exports the proc macros for debug/release builds and switches to the dummy macro_rules! when under a feature dedicated to rust-analyzer. But this refactoring is trivial. And the proc macros may already be forwarded/re-exported from a user-facing non-proc-macro crate anyway.)
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
The issue names no file or test; start by tracing rust-analyzer's existing inlay-hint handling for macro_rules! invocations. Establish how the active rule and captured variables are identified, then verify completion against the one-occurrence restriction, including repeated uses and captures in + or * repetitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100