rust-lang/rust-analyzer · error
Cannot rename a non-local definition
Error message
Cannot rename a non-local definition
What it means
A `bail!` guard in `Definition::rename`: the definition resolves to a crate whose `CrateOrigin` is not local (a dependency, sysroot, or otherwise foreign crate), so the source text does not live in the current workspace and renaming it would not produce valid edits. It is a user-facing validation error, not a bug — the offending input is the symbol the user asked to rename.
Source
Thrown at crates/ide-db/src/rename.rs:101
}
impl<'db> Definition<'db> {
pub fn rename(
&self,
sema: &Semantics<'db, RootDatabase>,
new_name: &str,
rename_definition: RenameDefinition,
config: &RenameConfig,
) -> Result<SourceChange> {
// self.krate() returns None if
// self is a built-in attr, built-in type or tool module.
// it is not allowed for these defs to be renamed.
// cases where self.krate() is None is handled below.
let edition = if let Some(krate) = self.krate(sema.db) {
// Can we not rename non-local items?
// Then bail if non-local
if !krate.origin(sema.db).is_local() {
bail!("Cannot rename a non-local definition")
}
krate.edition(sema.db)
} else {
Edition::LATEST
};
match *self {
Definition::Module(module) => rename_mod(sema, module, new_name),
Definition::ToolModule(_) => {
bail!("Cannot rename a tool module")
}
Definition::BuiltinType(_) => {
bail!("Cannot rename builtin type")
}
Definition::BuiltinAttr(_) => {
bail!("Cannot rename a builtin attr.")
}
Definition::SelfType(_) => bail!("Cannot rename `Self`"),View on GitHub (pinned to e8f7e90aa3)
Solutions
- Rename a local definition (one defined in workspace source) instead of one imported from a dependency or the sysroot
- If you own the dependency, rename it there and update the dependency version rather than in the consumer
- Suppress or ignore the rename action for foreign symbols in editor integration
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ide-db/src/rename.rs:101 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/d767fcb1ad27e512.
Report an issue: GitHub.