{"record":{"id":"91b47c497c81135d","repo":"rust-lang/rust-analyzer","slug":"invalid-name-not-an-identifier","errorCode":null,"errorMessage":"Invalid name `{}`: not an identifier","messagePattern":"Invalid name `(.+?)`: not an identifier","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ide-db/src/rename.rs","lineNumber":382,"sourceCode":"                bail!(\n                    \"Invalid name `{}`: not a lifetime identifier\",\n                    new_name.display(sema.db, edition)\n                );\n            }\n            IdentifierKind::Ident => {\n                new_name = Name::new_lifetime(&format!(\"'{}\", new_name.as_str()))\n            }\n            IdentifierKind::Lifetime => (),\n            IdentifierKind::LowercaseSelf => bail!(\n                \"Invalid name `{}`: not a lifetime identifier\",\n                new_name.display(sema.db, edition)\n            ),\n        }\n    } else {\n        match ident_kind {\n            IdentifierKind::Lifetime => {\n                cov_mark::hit!(rename_not_an_ident_ref);\n                bail!(\"Invalid name `{}`: not an identifier\", new_name.display(sema.db, edition));\n            }\n            IdentifierKind::Ident => cov_mark::hit!(rename_non_local),\n            IdentifierKind::Underscore => (),\n            IdentifierKind::LowercaseSelf => {\n                bail!(\n                    \"Invalid name `{}`: cannot rename to `self`\",\n                    new_name.display(sema.db, edition)\n                );\n            }\n        }\n    }\n\n    let def = convert_to_def_in_trait(sema.db, def);\n    let usages = def.usages(sema).all();\n\n    if !usages.is_empty() && ident_kind == IdentifierKind::Underscore {\n        cov_mark::hit!(rename_underscore_multiple);\n        bail!(\"Cannot rename reference to `_` as it is being referenced multiple times\");","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-db/src/rename.rs#L364-L400","documentation":"For non-lifetime definitions, `rename_reference` requires the classified name to be `Ident` or `Underscore`. A lifetime-shaped name (starts with `'`, classified `IdentifierKind::Lifetime`) is invalid for ordinary identifiers, so the rename bails with \"Invalid name `{}`: not an identifier\". `cov_mark::hit!(rename_not_an_ident_ref)` marks this path in tests.","triggerScenarios":"Renaming any non-lifetime `Definition` (e.g. a local variable, function, or module) with a lifetime-shaped new name such as `\"'a\"` at crates/ide-db/src/rename.rs:382.","commonSituations":"User selects a variable like `x` and types `'a` into the rename box (often by accidentally leaving an apostrophe from a previous lifetime rename), and the IDE rejects it.","solutions":["Remove the leading apostrophe and pass a plain identifier (e.g. `y` instead of `'y`).","If renaming a lifetime was intended, place the cursor on the lifetime parameter first.","Client-side, strip or reject names beginning with `'` when the target is not a lifetime."],"exampleFix":"// before\nrename(local_def, \"'a\")?; // Err: not an identifier\n// after\nrename(local_def, \"a\")?; // ok","handlingStrategy":"validation","validationCode":"if !is_lifetime_target(def) && new_name.starts_with('\\'') {\n    return Err(anyhow!(\"identifiers must not start with an apostrophe\"));\n}","typeGuard":"fn is_plain_identifier(s: &str) -> bool {\n    let mut cs = s.chars();\n    matches!(cs.next(), Some(c) if c.is_ascii_alphabetic() || c == '_') && cs.all(|c| c.is_ascii_alphanumeric() || c == '_')\n}","tryCatchPattern":"match def.rename(sema, new_name, ...) {\n    Err(e) if e.to_string().contains(\"not an identifier\") => eprintln!(\"drop the leading apostrophe for non-lifetime names\"),\n    other => other?,\n}","preventionTips":["Strip stray leading `'` from rename input unless the target is a lifetime.","Match the IdentifierKind classification to the definition kind before renaming.","Keep per-target-kind input validation in the client."],"tags":["rust","ide","rename","identifier-validation"],"backgroundTag":"invalid-identifier-name","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"}