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> |
//
// 
//
// #### 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
- Place the cursor directly on the identifier/name token to rename and retry.
- Check that the file content and cursor position sent to the LSP server are in sync (re-send didChange/didOpen).
- 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
- Cursor must sit on the identifier, not on whitespace/comments/literals
- Refresh the document position after edits before issuing rename
- Use hover or document-highlight as a pre-check that the symbol resolves
- Handle the LSP PrepareRenameResponse::None case gracefully in editors
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
- No file available to rename
- inconsistent text range
- Cannot rename builtin type
- Invalid name `{}`: cannot rename to a keyword
- Invalid name `{}`: {}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/97e91539aba0665e.
Report an issue: GitHub.