rust-lang/rust-analyzer · error · SsrError
Unknown node kind '{}'
Error message
Unknown node kind '{}' What it means
NodeKind::from converts a kind-constraint name into a NodeKind enum; in this codebase the only accepted name is "literal". Any other identifier passed to kind(...) triggers this error naming the unknown kind. This runs after the ident check in parse_constraint, so the syntax was valid but the vocabulary was not.
Source
Thrown at crates/ide-ssr/src/parsing.rs:347
x => bail!("Unsupported constraint type '{}'", x),
}
}
fn expect_token(tokens: &mut std::vec::IntoIter<Token>, expected: &str) -> Result<(), SsrError> {
if let Some(t) = tokens.next() {
if t.text == expected {
return Ok(());
}
bail!("Expected {} found {}", expected, t.text);
}
bail!("Expected {} found end of stream", expected);
}
impl NodeKind {
fn from(name: &SmolStr) -> Result<NodeKind, SsrError> {
Ok(match name.as_str() {
"literal" => NodeKind::Literal,
_ => bail!("Unknown node kind '{}'", name),
})
}
}
impl Placeholder {
fn new(name: SmolStr, constraints: Vec<Constraint>) -> Self {
Self {
stand_in_name: format!("__placeholder_{name}"),
constraints,
ident: Var(name.to_string()),
}
}
}
impl Display for Var {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "${}", self.0)
}View on GitHub (pinned to e8f7e90aa3)
Solutions
- Use kind(literal), the only supported node kind
- Wrap a negative case with not(): not(kind(literal)) to express 'anything but literal'
- Check the SSR documentation for currently supported constraint kinds before extending patterns
Example fix
// before let pattern = "$x:kind(expr)"; // after let pattern = "$x:kind(literal)";
Defensive patterns
Strategy: validation
Validate before calling
const KNOWN_NODE_KINDS: &[&str] = &["literal"];
fn all_kind_names_known(p: &str) -> bool {
p.match_indices("kind(")
.filter_map(|(i, _)| {
let rest = &p[i + 5..];
let end = rest.find(')')?;
Some(rest[..end].trim().to_string())
})
.all(|name| KNOWN_NODE_KINDS.contains(&name.as_str()))
}
Try / catch
match parse_pattern(pattern) {
Ok(p) => use_pattern(p),
Err(e) if e.message.contains("Unknown node kind") => {
eprintln!("Only 'literal' is a supported kind in this SSR version");
}
Err(e) => return Err(e),
} Prevention
- Use only documented kind names (currently 'literal')
- Match case exactly (lowercase 'literal')
- Do not assume rust-analyzer SyntaxKind names work in constraints
- Verify constraint vocabulary against the SSR version in use
When it happens
Trigger: Writing kind(node), kind(expr), kind(anything) — any ident other than literal — in an SSR placeholder constraint.
Common situations: Guessing at supported node kinds from rust-analyzer's broader SyntaxKind names; porting patterns from other tools with richer kind vocabularies; case mistakes such as kind(Literal).
Related errors
- Expected ident, found {:?} while parsing kind constraint
- Unsupported constraint type '{}'
- Expected {} found {}
- Expected {} found end of stream
- Failed to parse pattern: {}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/f14f12fd1806e6bb.
Report an issue: GitHub.