rust-lang/rust-analyzer · error · SsrError

Expected {} found end of stream

Error message

Expected {} found end of stream

What it means

Same expect_token check as 'Expected {} found {}', but this variant fires when the token stream is exhausted: the expected token (e.g. the closing ')' of a constraint) was never present. The pattern simply ends prematurely inside a constraint.

Source

Thrown at crates/ide-ssr/src/parsing.rs:340

        }
        "not" => {
            expect_token(tokens, "(")?;
            let sub = parse_constraint(tokens)?;
            expect_token(tokens, ")")?;
            Ok(Constraint::Not(Box::new(sub)))
        }
        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()),
        }

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Close all open constraint parentheses: kind(...), not(...)
  2. Complete the truncated pattern and re-run the parse
  3. If building patterns programmatically, validate balanced parens before calling the API

Example fix

// before
let pattern = "$x:kind(literal";
// after
let pattern = "$x:kind(literal)";
Defensive patterns

Strategy: validation

Validate before calling

fn complete_constraints(p: &str) -> bool {
    let mut depth = 0i32;
    for c in p.chars() {
        match c {
            '(' => depth += 1,
            ')' => depth -= 1,
            _ => {}
        }
    }
    // pattern must not end inside an open constraint
    depth == 0 && !p.trim_end().ends_with('(')
}

Try / catch

match parse_pattern(pattern) {
    Ok(p) => use_pattern(p),
    Err(e) if e.message.contains("end of stream") => {
        eprintln!("Pattern ended mid-constraint; close all parentheses");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Truncated pattern input such as '$x:kind(literal' or '$x:not(' reaching parse_constraint's expect_token call with an empty iterator.

Common situations: Cutting off an SSR pattern mid-edit in the search box; programmatically building patterns and truncating strings; missing closing brace/paren combinations that consume the rest of the input.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/162c16b004aa0b6c. Report an issue: GitHub.