{"record":{"id":"95a78768aec7d683","repo":"rust-lang/rust-analyzer","slug":"invalid-name","errorCode":null,"errorMessage":"Invalid name `{}`: {}","messagePattern":"Invalid name `(.+?)`: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ide-db/src/rename.rs","lineNumber":833,"sourceCode":"impl IdentifierKind {\n    pub fn classify(edition: Edition, new_name: &str) -> Result<(Name, IdentifierKind)> {\n        match parser::LexedStr::single_token(edition, new_name) {\n            Some(res) => match res {\n                (SyntaxKind::IDENT, _) => Ok((Name::new_root(new_name), IdentifierKind::Ident)),\n                (T![_], _) => {\n                    Ok((Name::new_symbol_root(sym::underscore), IdentifierKind::Underscore))\n                }\n                (SyntaxKind::LIFETIME_IDENT, _) if new_name != \"'static\" && new_name != \"'_\" => {\n                    Ok((Name::new_lifetime(new_name), IdentifierKind::Lifetime))\n                }\n                _ if SyntaxKind::from_keyword(new_name, edition).is_some() => match new_name {\n                    \"self\" => Ok((Name::new_root(new_name), IdentifierKind::LowercaseSelf)),\n                    \"crate\" | \"super\" | \"Self\" => {\n                        bail!(\"Invalid name `{}`: cannot rename to a keyword\", new_name)\n                    }\n                    _ => Ok((Name::new_root(new_name), IdentifierKind::Ident)),\n                },\n                (_, Some(syntax_error)) => bail!(\"Invalid name `{}`: {}\", new_name, syntax_error),\n                (_, None) => bail!(\"Invalid name `{}`: not an identifier\", new_name),\n            },\n            None => bail!(\"Invalid name `{}`: not an identifier\", new_name),\n        }\n    }\n}\n","sourceCodeStart":815,"sourceCodeEnd":840,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-db/src/rename.rs#L815-L840","documentation":"`IdentifierKind::classify` (crates/ide-db/src/rename.rs:833) rejects a proposed rename name that lexes as a single token but carries a parser syntax error. The token's associated error message (`syntax_error`) is interpolated into 'Invalid name `{}`: {}'. This is the generic malformed-token path of name validation.","triggerScenarios":"Renaming to a token the Rust lexer/parser rejects, e.g. an empty raw identifier `r#`, a malformed literal-as-name, or any single token with an attached lexical error; fires at the `(_, Some(syntax_error))` arm.","commonSituations":"Copy-pasting a name with stray characters; automated tooling passing a placeholder like `\"$name\"` or `\"foo bar\"` fragments that still tokenize; renaming to `r#` with no identifier after the raw prefix.","solutions":["Read the interpolated syntax_error in the message; it names the exact lexical problem.","Supply a plain ASCII identifier matching [A-Za-z_][A-Za-z0-9_]* (or a well-formed lifetime for lifetimes).","For raw identifiers, use the complete form `r#name`, never a bare `r#` prefix."],"exampleFix":"// before\n{ \"newName\": \"r#\" }\n\n// after\n{ \"newName\": \"r#type\" }","handlingStrategy":"validation","validationCode":"fn validate_single_token(new_name: &str) -> Result<(), String> {\n    if new_name.starts_with(\"r#\") && new_name.len() <= 2 {\n        return Err(\"raw identifier must be r# followed by a name\".into());\n    }\n    Ok(())\n}","typeGuard":"fn looks_like_well_formed_token(s: &str) -> bool {\n    !s.is_empty() && !s.contains(char::is_whitespace)\n        && !(s == \"r#\")\n}","tryCatchPattern":null,"preventionTips":["Never send a bare `r#` prefix; always complete raw identifiers (r#name).","Strip stray characters/whitespace from user input before issuing rename.","Parse the interpolated syntax_error in the message for the exact lexical problem.","Test scripted renames with realistic names, not placeholders like $name."],"tags":["rust-analyzer","rename","lexer","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"}