{"id":"ffc796ac076aa9ca","repo":"rust-lang/rust","slug":"because-the-current-token-is-a","errorCode":null,"errorMessage":"because the current token is a '{'","messagePattern":"because the current token is a '\\{'","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_parse/src/parser/cfg_select.rs","lineNumber":24,"sourceCode":"\nuse crate::exp;\nuse crate::parser::{AttrWrapper, ForceCollect, Parser, Restrictions, Trailing, UsePreAttrPos};\n\n#[derive(Default)]\npub struct CfgSelectBranchAttrSpans {\n    pub attrs: Vec<Span>,\n    pub doc_comments: Vec<Span>,\n}\n\nimpl<'a> Parser<'a> {\n    /// Parses a `TokenTree` consisting either of `{ /* ... */ }` optionally followed by a comma\n    /// (and strip the braces and the optional comma) or an expression followed by a comma\n    /// (and strip the comma).\n    pub fn parse_delimited_token_tree(&mut self) -> PResult<'a, TokenStream> {\n        if self.token == token::OpenBrace {\n            // Strip the outer '{' and '}'.\n            match self.parse_token_tree() {\n                TokenTree::Token(..) => unreachable!(\"because the current token is a '{{'\"),\n                TokenTree::Delimited(.., tts) => {\n                    // Optionally end with a comma.\n                    let _ = self.eat(exp!(Comma));\n                    return Ok(tts);\n                }\n            }\n        }\n        let expr = self.collect_tokens(None, AttrWrapper::empty(), ForceCollect::Yes, |p, _| {\n            p.parse_expr_res(Restrictions::STMT_EXPR, AttrWrapper::empty())\n                .map(|(expr, _)| (expr, Trailing::No, UsePreAttrPos::No))\n        })?;\n        if !classify::expr_is_complete(&expr)\n            && self.token != token::CloseBrace\n            && self.token != token::Eof\n        {\n            self.expect(exp!(Comma))?;\n        } else {\n            let _ = self.eat(exp!(Comma));","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_parse/src/parser/cfg_select.rs#L6-L42","documentation":"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.","triggerScenarios":"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 `{`.","commonSituations":"Compiler-internal regression in the unstable `cfg_select!` feature; not triggerable through ordinary `#[cfg]` / `#[cfg_attr]` attributes.","solutions":["Report as a rustc ICE including the `cfg_select!` invocation and the backtrace","Replace `cfg_select!` with standard `#[cfg]`/`#[cfg_attr]` attributes as a workaround","Confirm the issue is feature-gated (cfg_select is unstable) by removing the `#![feature(cfg_select)]` usage"],"exampleFix":"// before: unstable cfg_select triggers the panic\n#![feature(cfg_select)]\ncfg_select! {\n    { /* branch */ }\n}\n// after: use standard cfg attributes\n#[cfg(condition)]\n/* item */","handlingStrategy":"validation","validationCode":"use rustc_ast::token::TokenKind;\nfn current_token_is_brace(tok: &TokenKind) -> bool {\n    matches!(tok, TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_))\n}\n// peek before parsing a cfg-select arm\nif current_token_is_brace(&parser.token.kind) {\n    return Err(\"cfg-select cannot start with a brace; expected attribute or ident\");\n}","typeGuard":null,"tryCatchPattern":"use std::panic;\nlet parsed = panic::catch_unwind(panic::AssertUnwindSafe(|| parser.parse_cfg_select()));\nif parsed.is_err() { /* recover by skipping to matching brace */ }","preventionTips":["Before invoking cfg-select parsing, peek the current token; the grammar does not begin with a brace.","Drive attribute/identifier-led parsing for cfg directives; brace-led input means a malformed `cfg!` macro invocation.","If you splice macro fragments into a cfg context, ensure the splice point is at an attribute or ident token, not a block.","Treat a leading `{` as a structural bug in your token-stream construction and recover by skipping the balanced block."],"tags":["compiler-ice","parser","cfg-select","unstable-feature"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}