rust-lang / rust-lang/rust-analyzer

Wrong range when request at edited std

Open
#23,199 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lsp A-project-model Broken Window C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: 2026-07-20 tag release (2026-07-13 no this bug)

rustc version: rustc 1.97.0-nightly (36ba2c771 2026-04-23)

editor or extension: Vim coc-rust-analyzer or naked rust-analyzer

code snippet to reproduce:
In ~/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/non_null.rs

#[stable(feature = "nonnull", since = "1.25.0")]
#[repr(transparent)]
#[rustc_nonnull_optimization_guaranteed]
#[rustc_diagnostic_item = "NonNull"]
pub struct NonNull<T: PointeeSized> {
    pointer: crate::pattern_type!(*const T is !null),
    i$0
}

Outputs:

Error on resolve complete item from rust-analyzer: {
  "label": "impl",
  "kind": 14,
  "preselect": true,
  "sortText": "7ffffff6",
  "filterText": "impl",
  "insertTextFormat": 2,
  "textEdit": {
    "newText": "impl $1 {\n    $0\n}",
    "insert": {
      "start": { "line": 76, "character": 0 },
      "end":   { "line": 75, "character": 5 }
    },
    "replace": {
      "start": { "line": 76, "character": 0 },
      "end":   { "line": 76, "character": 0 }
    }
  }
}
ResponseError: Received a completion with overlapping edits, this is not LSP-compliant

Better reproduction

  1. Insert a space before pub struct NonNull
  2. Cursor on NonNull, use hover doc, response range is based on the original, not the edited document

Expect "NonNull", Actual " NonNul"

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 the Better reproduction with the completion and hover requests, then trace rust-analyzer's LSP text-edit and range handling. Compare the response ranges with the edited document after inserting a space before pub struct NonNull. Done means completion and hover ranges use the edited document and no overlapping edits or shifted text are returned.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.