rust-lang / rust-lang/rust-analyzer

Off-by-one error when performing autocomplete on an expression inside a proc macro

Open
#16,127 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion A-proc-macro C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In recent versions of Rust Analyzer, inlay hints and completions seem to be broken for expressions passed to proc macros which emit the input expression as-is. See #16004 for hints, but completions also seem to be having trouble with the wrong expression being used to compute completions. For example, consider the following case:
Screenshot 2023-12-14 at 10 42 43 AM

Rust Analyzer correctly infers the type of v to be a Result<BytesMut, ...>, but the completions are for the BytesMut rather than the Result. This used to behave fine in previous versions of Rust Analyzer, so something seems to have changed.

rust-analyzer version: 0.3.1766-standalone

rustc version: rustc 1.76.0-nightly (3340d49d2 2023-12-12)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing autocomplete for an expression passed to a proc macro that emits its input unchanged, using the reported Rust Analyzer and rustc versions as context. Trace which expression is used to compute completions and compare it with the inferred Result type; done when completions target the Result rather than the inner BytesMut.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.