rust-lang/rust · critical

because the current token is a '{'

Error message

because the current token is a '{'

What it means

Internal `unreachable!` in `parse_delimited_token_tree`, used when parsing branches of the experimental `cfg_select!` macro. When the current token is `{`, `parse_token_tree` is contractually guaranteed to return a `TokenTree::Delimited`; the `TokenTree::Token` match arm is unreachable by construction. Hitting it means the lower-level token-tree parser returned an unexpected variant, signalling a compiler bug.

Source

Thrown at compiler/rustc_parse/src/parser/cfg_select.rs:24

use crate::exp;
use crate::parser::{AttrWrapper, ForceCollect, Parser, Restrictions, Trailing, UsePreAttrPos};

#[derive(Default)]
pub struct CfgSelectBranchAttrSpans {
    pub attrs: Vec<Span>,
    pub doc_comments: Vec<Span>,
}

impl<'a> Parser<'a> {
    /// Parses a `TokenTree` consisting either of `{ /* ... */ }` optionally followed by a comma
    /// (and strip the braces and the optional comma) or an expression followed by a comma
    /// (and strip the comma).
    pub fn parse_delimited_token_tree(&mut self) -> PResult<'a, TokenStream> {
        if self.token == token::OpenBrace {
            // Strip the outer '{' and '}'.
            match self.parse_token_tree() {
                TokenTree::Token(..) => unreachable!("because the current token is a '{{'"),
                TokenTree::Delimited(.., tts) => {
                    // Optionally end with a comma.
                    let _ = self.eat(exp!(Comma));
                    return Ok(tts);
                }
            }
        }
        let expr = self.collect_tokens(None, AttrWrapper::empty(), ForceCollect::Yes, |p, _| {
            p.parse_expr_res(Restrictions::STMT_EXPR, AttrWrapper::empty())
                .map(|(expr, _)| (expr, Trailing::No, UsePreAttrPos::No))
        })?;
        if !classify::expr_is_complete(&expr)
            && self.token != token::CloseBrace
            && self.token != token::Eof
        {
            self.expect(exp!(Comma))?;
        } else {
            let _ = self.eat(exp!(Comma));

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Report as a rustc ICE including the `cfg_select!` invocation and the backtrace
  2. Replace `cfg_select!` with standard `#[cfg]`/`#[cfg_attr]` attributes as a workaround
  3. Confirm the issue is feature-gated (cfg_select is unstable) by removing the `#![feature(cfg_select)]` usage

Example fix

// before: unstable cfg_select triggers the panic
#![feature(cfg_select)]
cfg_select! {
    { /* branch */ }
}
// after: use standard cfg attributes
#[cfg(condition)]
/* item */
Defensive patterns

Strategy: validation

Validate before calling

use rustc_ast::token::TokenKind;
fn current_token_is_brace(tok: &TokenKind) -> bool {
    matches!(tok, TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_))
}
// peek before parsing a cfg-select arm
if current_token_is_brace(&parser.token.kind) {
    return Err("cfg-select cannot start with a brace; expected attribute or ident");
}

Try / catch

use std::panic;
let parsed = panic::catch_unwind(panic::AssertUnwindSafe(|| parser.parse_cfg_select()));
if parsed.is_err() { /* recover by skipping to matching brace */ }

Prevention

When it happens

Trigger: Parsing a brace-delimited branch of `cfg_select!` where `parse_token_tree` yields a bare `Token` instead of a `Delimited` group despite the current token being `{`.

Common situations: Compiler-internal regression in the unstable `cfg_select!` feature; not triggerable through ordinary `#[cfg]` / `#[cfg_attr]` attributes.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/ffc796ac076aa9ca.json. Report an issue: GitHub.