rust-lang/rust-analyzer · error

No references found at position

Error message

No references found at position

What it means

prepare_rename (and rename) require that at least one renamable definition exists at the given FilePosition. If find_definitions returns nothing that can be renamed (or reduce produced no entries), the operation cannot proceed and this error is thrown. It is the standard 'cursor is not on a renamable symbol' error surfaced to editors.

Source

Thrown at crates/ide/src/rename.rs:111

            Ok(match kind {
                SyntaxKind::LIFETIME => {
                    TextRange::new(frange.range.start() + TextSize::from(1), frange.range.end())
                }
                _ => frange.range,
            })
        })
        .reduce(|acc, cur| match (acc, cur) {
            // ensure all ranges are the same
            (Ok(acc_inner), Ok(cur_inner)) if acc_inner == cur_inner => Ok(acc_inner),
            (e @ Err(_), _) | (_, e @ Err(_)) => e,
            _ => bail!("inconsistent text range"),
        });

    match res {
        // ensure at least one definition was found
        Some(res) => res.map(|range| RangeInfo::new(range, ())),
        None => bail!("No references found at position"),
    }
}

// Feature: Rename
//
// Renames the item below the cursor and all of its references
//
// | Editor  | Shortcut |
// |---------|----------|
// | VS Code | <kbd>F2</kbd> |
//
// ![Rename](https://user-images.githubusercontent.com/48062697/113065582-055aae80-91b1-11eb-8ade-2b58e6d81883.gif)
//
// #### Magic Renames
//
// rust-analyzer supports some special renames that do additional magic:
//
//  - **Anonymous lifetime renames**. You can rename `'_` to any lifetime name (the new name must start with `'`),

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Place the cursor directly on the identifier/name token to rename and retry.
  2. Check that the file content and cursor position sent to the LSP server are in sync (re-send didChange/didOpen).
  3. Use find references or hover first to confirm the symbol is semantically resolvable at that position.

Example fix

// before: rename request at offset inside a comment
// fn foo() {}  <- cursor here
// after: request at offset on `foo` token itself
fn foo() {}
Defensive patterns

Strategy: validation

Validate before calling

// Check the position resolves to a symbol before renaming
let symbol = client.hover(file_uri, position).await?;
if symbol.is_none() {
    // cursor not on a renamable item; skip rename
}

Type guard

fn position_on_token(line: &str, col: usize) -> bool {
    !line.is_empty() && col <= line.len()
        && line[..col].chars().last()
            .map_or(false, |c| c.is_alphanumeric() || c == '_')
}

Try / catch

match prepare_rename(db, pos) {
    Ok(info) => start_rename_session(info),
    Err(e) if e.to_string().contains("No references found") => {
        notify_user("Place the cursor on an identifier to rename");
    }
    Err(e) => report(e),
}

Prevention

When it happens

Trigger: Calling prepare_rename at an offset on whitespace, comments, string literals, keywords, or non-identifier tokens; also raised by rename via format_err when sema cannot attach the file or when no SourceChange ops are produced.

Common situations: Editors firing rename while the cursor is at end-of-line, inside a comment or doc text, on a crate/attribute path segment that is not renamable, or on stale positions after the file changed without a document sync.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/97e91539aba0665e. Report an issue: GitHub.