{"record":{"id":"22c3574fe8a9fd10","repo":"rust-lang/rust-analyzer","slug":"expected-ident-found-while-parsing-kind-cons","errorCode":null,"errorMessage":"Expected ident, found {:?} while parsing kind constraint","messagePattern":"Expected ident, found (.+?) while parsing kind constraint","errorType":"validation","errorClass":"SsrError","httpStatus":null,"severity":"error","filePath":"crates/ide-ssr/src/parsing.rs","lineNumber":318,"sourceCode":"    }\n    let name = name.ok_or_else(|| SsrError::new(\"Placeholder ($) with no name\"))?;\n    Ok(Placeholder::new(name, constraints))\n}\n\nfn parse_constraint(tokens: &mut std::vec::IntoIter<Token>) -> Result<Constraint, SsrError> {\n    let constraint_type = tokens\n        .next()\n        .ok_or_else(|| SsrError::new(\"Found end of placeholder while looking for a constraint\"))?\n        .text\n        .to_string();\n    match constraint_type.as_str() {\n        \"kind\" => {\n            expect_token(tokens, \"(\")?;\n            let t = tokens.next().ok_or_else(|| {\n                SsrError::new(\"Unexpected end of constraint while looking for kind\")\n            })?;\n            if t.kind != SyntaxKind::IDENT {\n                bail!(\"Expected ident, found {:?} while parsing kind constraint\", t.kind);\n            }\n            expect_token(tokens, \")\")?;\n            Ok(Constraint::Kind(NodeKind::from(&t.text)?))\n        }\n        \"not\" => {\n            expect_token(tokens, \"(\")?;\n            let sub = parse_constraint(tokens)?;\n            expect_token(tokens, \")\")?;\n            Ok(Constraint::Not(Box::new(sub)))\n        }\n        x => bail!(\"Unsupported constraint type '{}'\", x),\n    }\n}\n\nfn expect_token(tokens: &mut std::vec::IntoIter<Token>, expected: &str) -> Result<(), SsrError> {\n    if let Some(t) = tokens.next() {\n        if t.text == expected {\n            return Ok(());","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/ide-ssr/src/parsing.rs#L300-L336","documentation":"Inside a kind(...) constraint, SSR expects exactly one identifier naming the node kind, then a closing ')'. If the token found where the identifier should be is not a SyntaxKind::IDENT, this error reports the unexpected token kind via {:?}. It comes from parse_constraint, which is reachable both directly from parse_placeholder and recursively via the 'not(...)' constraint.","triggerScenarios":"Writing constraints like kind(42), kind(\"literal\"), kind() where the next token is a literal/paren/EOF rather than an ident, or kind(kind) with a keyword-ish token that does not lex as IDENT.","commonSituations":"Quoting the kind name out of habit (kind(\"literal\")); forgetting the argument entirely (kind()); typos that leave punctuation inside the parentheses.","solutions":["Pass the kind name as a bare unquoted identifier: kind(literal)","Ensure exactly one identifier appears between kind( and )","Check the reported token kind in the message to see what the parser actually found"],"exampleFix":"// before\nlet pattern = \"$x:kind(\\\"literal\\\")\";\n// after\nlet pattern = \"$x:kind(literal)\";","handlingStrategy":"validation","validationCode":"fn valid_kind_constraint(p: &str) -> bool {\n    if let Some(idx) = p.find(\"kind(\") {\n        let rest = &p[idx + 5..];\n        let mut chars = rest.chars();\n        match chars.next() {\n            Some(c) if c.is_alphabetic() || c == '_' => {\n                // next non-ident char should be ')'\n                let ident_end = rest.find(|c: char| !(c.is_alphanumeric() || c == '_'));\n                matches!(ident_end.map(|e| rest[e..].starts_with(')')), Some(true))\n            }\n            _ => false, // missing or non-ident argument (e.g. quoted)\n        }\n    } else {\n        true\n    }\n}\n","typeGuard":null,"tryCatchPattern":"match parse_pattern(pattern) {\n    Ok(p) => use_pattern(p),\n    Err(e) if e.message.contains(\"while parsing kind constraint\") => {\n        eprintln!(\"kind() takes one unquoted identifier: kind(literal)\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Never quote the kind name","Always supply exactly one identifier inside kind(...)","Balance the parentheses of kind(...)","Remember not(...) parses its argument recursively with the same rules"],"tags":["rust","parsing","ssr","constraints"],"backgroundTag":"ssr-pattern-parse-error","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"}