{"record":{"id":"0e3a6164d6e8eb7a","repo":"rust-lang/rust-analyzer","slug":"cannot-rename-builtin-type","errorCode":null,"errorMessage":"Cannot rename builtin type","messagePattern":"Cannot rename builtin type","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ide-db/src/rename.rs","lineNumber":114,"sourceCode":"        // 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`\"),\n            Definition::Macro(mac) => rename_reference(\n                sema,\n                Definition::Macro(mac),\n                new_name,\n                rename_definition,\n                edition,\n                config,\n            ),\n            def => rename_reference(sema, def, new_name, rename_definition, edition, config),\n        }\n    }\n\n    /// Textual range of the identifier which will change when renaming this","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-db/src/rename.rs#L96-L132","documentation":"rust_analyzer's `Definition::rename` refuses to rename any `Definition::BuiltinType` (e.g. `u32`, `bool`, `str`). Builtin types are provided by the language/core crate and have no single definitional site to rewrite, so every reference would be ambiguous. The library deliberately bails instead of producing an incorrect SourceChange.","triggerScenarios":"Calling `Definition::rename` (public API, crates/ide-db/src/rename.rs:114) on a definition resolved to a builtin type, e.g. when the user invokes rename on the `i32` token in `let x: i32 = 0;`.","commonSituations":"Cursor placed on a primitive type name in source code and the editor issues a `textDocument/rename` LSP request; IDE plugins resolving the token to `hir::Namespace`-style builtin types rather than a user item.","solutions":["Rename the user-defined item instead; builtin types cannot be renamed.","To alias a builtin, introduce a type alias (`type MyInt = i32;`) manually.","In client code, check `matches!(def, Definition::BuiltinType(_))` before calling rename and surface a user-friendly message."],"exampleFix":"// before (rename request on builtin)\ndefinition.rename(sema, \"i64\", ...); // Err: Cannot rename builtin type\n// after\nif matches!(definition, Definition::BuiltinType(_)) {\n    return; // skip rename, show \"builtin types cannot be renamed\"\n}\ndefinition.rename(sema, \"i64\", ...)?;","handlingStrategy":"validation","validationCode":"fn can_rename(def: &Definition) -> bool {\n    !matches!(def, Definition::BuiltinType(_) | Definition::BuiltinAttr(_) | Definition::SelfType(_) | Definition::ToolModule(_))\n}","typeGuard":"fn is_renamable(def: &Definition) -> bool {\n    !matches!(def, Definition::BuiltinType(_))\n}","tryCatchPattern":"match def.rename(sema, new_name, ...) {\n    Err(e) if e.to_string().contains(\"Cannot rename builtin type\") => eprintln!(\"builtin types cannot be renamed\"),\n    Err(e) => return Err(e),\n    Ok(change) => apply(change),\n}","preventionTips":["Check the resolved Definition kind before issuing a rename request.","Hide the rename action in the UI when the cursor is on a primitive type token.","Prefer introducing type aliases instead of attempting builtin renames."],"tags":["rust","ide","rename","lsp"],"backgroundTag":"rename-not-supported-for-definition","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"}