{"record":{"id":"3ed1e3977e8ad97a","repo":"rust-lang/rust-analyzer","slug":"invalid-delimiter-delimiter","errorCode":null,"errorMessage":"invalid delimiter `{delimiter:?}`","messagePattern":"invalid delimiter `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/syntax/src/ast/make.rs","lineNumber":1363,"sourceCode":"    inner: impl IntoIterator<Item = ast::Meta>,\n) -> ast::CfgAttrMeta {\n    let inner = inner.into_iter().join(\", \");\n    ast_from_text(&format!(\"#![cfg_attr({predicate}, {inner})]\"))\n}\n\npub fn cfg_flag(flag: &str) -> ast::CfgPredicate {\n    ast_from_text(&format!(\"#![cfg({flag})]\"))\n}\n\npub fn token_tree(\n    delimiter: SyntaxKind,\n    tt: impl IntoIterator<Item = NodeOrToken<ast::TokenTree, SyntaxToken>>,\n) -> ast::TokenTree {\n    let (l_delimiter, r_delimiter) = match delimiter {\n        T!['('] => ('(', ')'),\n        T!['['] => ('[', ']'),\n        T!['{'] => ('{', '}'),\n        _ => panic!(\"invalid delimiter `{delimiter:?}`\"),\n    };\n    let tt = tt.into_iter().join(\"\");\n\n    ast_from_text(&format!(\"tt!{l_delimiter}{tt}{r_delimiter}\"))\n}\n\npub fn expr_let(pattern: ast::Pat, expr: ast::Expr) -> ast::LetExpr {\n    expr_from_text(&format!(\"while let {pattern} = {expr} {{}}\"))\n}\n\n#[track_caller]\nfn expr_from_text<E: Into<ast::Expr> + AstNode>(text: &str) -> E {\n    expr_from_text_with_edition(text, Edition::CURRENT)\n}\n\n#[track_caller]\nfn expr_from_text_with_edition<E: Into<ast::Expr> + AstNode>(text: &str, edition: Edition) -> E {\n    let parse = ast::Expr::parse(text, edition);","sourceCodeStart":1345,"sourceCodeEnd":1381,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/syntax/src/ast/make.rs#L1345-L1381","documentation":"`make::token_tree(delimiter, tt)` builds an `ast::TokenTree` by rendering `tt!(...)` with the given delimiter. It only accepts the three group-opening punct kinds `T!['(']`, `T!['[']`, `T!['{']`; any other `SyntaxKind` hits the `_` arm and panics with `invalid delimiter`. The FileChange/fmt/set_roots mention in the error metadata refers to unrelated same-workspace symbols and is not the throwing item.","triggerScenarios":"Calling `make::token_tree` with a `SyntaxKind` other than `T!['(']`, `T!['[']`, `T!['{']` — e.g. a closing-kind like `T![')']`, an arbitrary token kind, or a kind derived from a `tt::DelimiterKind` without handling `Invisible`.","commonSituations":"Mapping a `tt::DelimiterKind`/token kind to a make-delimiter with an incomplete match; delimiters read from token streams where `Invisible` maps to no punct kind; passing a closing delimiter kind by mistake.","solutions":["Pass exactly one of `T!['(']`, `T!['[']`, `T!['{']` (punctuation SyntaxKinds, not `DelimiterKind` values).","Map `tt::DelimiterKind` explicitly: Parenthesis→`T!['(']`, Brace→`T!['{']`, Bracket→`T!['[']`, and handle/skip `Invisible` before calling.","Validate the kind with a match before calling and fall back to a default delimiter for unexpected values."],"exampleFix":"// before\nmake::token_tree(T![')'], items); // panics: invalid delimiter\n// after\nmake::token_tree(T!['('], items);","handlingStrategy":"validation","validationCode":"fn is_valid_delimiter(kind: syntax::SyntaxKind) -> bool {\n    use syntax::SyntaxKind::*;\n    matches!(kind, T!['('] | T!['['] | T!['{'])\n}\n// if !is_valid_delimiter(kind) { return Err(...) }","typeGuard":"fn to_delimiters(kind: syntax::SyntaxKind) -> Option<(char, char)> {\n    use syntax::SyntaxKind as K;\n    match kind {\n        K::L_PAREN => Some(('(', ')')),\n        K::L_BRACK => Some(('[', ']')),\n        K::L_CURLY => Some(('{', '}')),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Only pass `T!['(']`, `T!['[']`, or `T!['{']` to `make::token_tree`.","Convert `tt::DelimiterKind` to punct SyntaxKinds via an exhaustive match and handle `Invisible` separately.","Never pass closing-delimiter or non-punct SyntaxKinds."],"tags":["ast","syntax-kind","panic","api-misuse"],"backgroundTag":"invalid-delimiter-kind","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"}