{"record":{"id":"8a21b92f3331af8c","repo":"rust-lang/rust-analyzer","slug":"cannot-rename-a-builtin-attr","errorCode":null,"errorMessage":"Cannot rename a builtin attr.","messagePattern":"Cannot rename a builtin attr\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ide-db/src/rename.rs","lineNumber":117,"sourceCode":"            // 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\n    /// `Definition`. Note that builtin types can't be\n    /// renamed and extern crate names will report its range, though a rename will introduce\n    /// an alias instead.","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-db/src/rename.rs#L99-L135","documentation":"`Definition::rename` rejects renaming `Definition::BuiltinAttr` — attributes the compiler interprets natively (e.g. `#[derive]`, `#[test]`, `#[inline]`). These names are fixed by rustc; renaming them would break the code, so rust_analyzer bails early with this message.","triggerScenarios":"Invoking `Definition::rename` (crates/ide-db/src/rename.rs:117) when the resolved definition is a builtin attribute, typically from a rename request on the `derive` in `#[derive(Debug)]`.","commonSituations":"A user tries to rename `derive`, `test`, `inline`, or similar built-in attribute names in their editor and gets this error back as an LSP error response.","solutions":["Do not rename builtin attributes; they are part of the language.","If a custom attribute with the same name is wanted, define your own proc-macro attribute and rename that instead.","Guard callers with a check for `Definition::BuiltinAttr(_)` before calling rename."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if matches!(def, Definition::BuiltinAttr(_)) {\n    return Err(anyhow!(\"builtin attributes like #[derive] cannot be renamed\"));\n}","typeGuard":"fn is_builtin_attr(def: &Definition) -> bool {\n    matches!(def, Definition::BuiltinAttr(_))\n}","tryCatchPattern":"match def.rename(sema, new_name, ...) {\n    Err(e) if e.to_string().contains(\"builtin attr\") => show_hint(\"built-in attributes are fixed by rustc\"),\n    other => other?,\n}","preventionTips":["Never offer rename on tokens inside `#[...]` that resolve to builtin attributes.","Whitelist known builtin attribute names (derive, test, inline, ...) in client-side checks.","Treat attribute name edits as code changes, not rename operations."],"tags":["rust","ide","rename","attributes"],"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"}