{"record":{"id":"d767fcb1ad27e512","repo":"rust-lang/rust-analyzer","slug":"cannot-rename-a-non-local-definition","errorCode":null,"errorMessage":"Cannot rename a non-local definition","messagePattern":"Cannot rename a non-local definition","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ide-db/src/rename.rs","lineNumber":101,"sourceCode":"}\n\nimpl<'db> Definition<'db> {\n    pub fn rename(\n        &self,\n        sema: &Semantics<'db, RootDatabase>,\n        new_name: &str,\n        rename_definition: RenameDefinition,\n        config: &RenameConfig,\n    ) -> Result<SourceChange> {\n        // self.krate() returns None if\n        // self is a built-in attr, built-in type or tool module.\n        // it is not allowed for these defs to be renamed.\n        // cases where self.krate() is None is handled below.\n        let edition = if let Some(krate) = self.krate(sema.db) {\n            // Can we not rename non-local items?\n            // Then bail if non-local\n            if !krate.origin(sema.db).is_local() {\n                bail!(\"Cannot rename a non-local definition\")\n            }\n            krate.edition(sema.db)\n        } else {\n            Edition::LATEST\n        };\n\n        match *self {\n            Definition::Module(module) => rename_mod(sema, module, new_name),\n            Definition::ToolModule(_) => {\n                bail!(\"Cannot rename a tool module\")\n            }\n            Definition::BuiltinType(_) => {\n                bail!(\"Cannot rename builtin type\")\n            }\n            Definition::BuiltinAttr(_) => {\n                bail!(\"Cannot rename a builtin attr.\")\n            }\n            Definition::SelfType(_) => bail!(\"Cannot rename `Self`\"),","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-db/src/rename.rs#L83-L119","documentation":"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.","triggerScenarios":"Thrown at crates/ide-db/src/rename.rs:101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}