{"id":"89e2a3fda6c37dcf","repo":"rust-lang/rust","slug":"should-be-attrtokentree-delimited-not-delim-to","errorCode":null,"errorMessage":"Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}","messagePattern":"Should be `AttrTokenTree::Delimited`, not delim tokens: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_ast/src/attr/mod.rs","lineNumber":526,"sourceCode":"                    };\n                    iter.next();\n                }\n                let span = span.with_hi(segments.last().unwrap().ident.span.hi());\n                Path { span, segments }\n            }\n            Some(TokenTree::Delimited(\n                _span,\n                _spacing,\n                Delimiter::Invisible(InvisibleOrigin::MetaVar(\n                    MetaVarKind::Meta { .. } | MetaVarKind::Path,\n                )),\n                _stream,\n            )) => {\n                // This path is currently unreachable in the test suite.\n                unreachable!()\n            }\n            Some(TokenTree::Token(Token { kind, .. }, _)) if kind.is_delim() => {\n                panic!(\"Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}\", tt);\n            }\n            _ => return None,\n        };\n        let list_closing_paren_pos = iter.peek().map(|tt| tt.span().hi());\n        let kind = MetaItemKind::from_tokens(iter)?;\n        let hi = match &kind {\n            MetaItemKind::NameValue(lit) => lit.span.hi(),\n            MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),\n            _ => path.span.hi(),\n        };\n        let span = path.span.with_hi(hi);\n        // FIXME: This parses `unsafe()` not as unsafe attribute syntax in `MetaItem`,\n        // but as a parenthesized list. This (and likely `MetaItem`) should be changed in\n        // such a way that builtin macros don't accept extraneous `unsafe()`.\n        Some(MetaItem { unsafety: Safety::Default, path, kind, span })\n    }\n}\n","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_ast/src/attr/mod.rs#L508-L544","documentation":"`panic!(\"Should be \\`AttrTokenTree::Delimited\\`, not delim tokens: {:?}\")` fires inside `MetaItem::from_tokens` when the attribute-token stream contains a bare `TokenTree::Token` whose kind is a delimiter (`(`, `[`, `{`) instead of the expected `AttrTokenTree::Delimited` wrapper. The attribute parser canonicalizes delimiters into the `Delimited` variant; encountering a raw delim token means the stream was assembled incorrectly (a non-canonical token stream).","triggerScenarios":"`MetaItem::from_attr_token_stream` walks the stream and finds `Some(TokenTree::Token(Token { kind, .. }, _))` where `kind.is_delim()` is true. Triggered when code constructs an `AttrTokenStream` by pushing raw delimiter tokens instead of wrapping them as `AttrTokenTree::Delimited`.","commonSituations":"Internal AST/tokenstream tooling that hand-builds attribute token streams. Bugs in token collection (`collect_tokens`) that fail to group matching delimiters. Macros that emit raw `(` / `[` / `{` tokens into attribute positions. Not reproducible from ordinary source; only via non-canonical streams.","solutions":["When building an `AttrTokenStream`, always wrap matched delimiters in `AttrTokenTree::Delimited(delim_span, delim_spacing, delimiter, inner_stream)`.","Re-run the failing case under the attribute parser's token collector rather than constructing the stream manually.","Audit recent changes to token collection / `break_last_token` logic that may have left delimiters ungrouped."],"exampleFix":"// before\nstream.push(AttrTokenTree::Token(Token::open_paren(span), Spacing::Alone));\n\n// after\nstream.push(AttrTokenTree::Delimited(\n    DelimSpan::single(span),\n    DelimSpacing::new(Spacing::Alone, Spacing::Alone),\n    Delimiter::Parenthesis,\n    inner_stream,\n));","handlingStrategy":"type-guard","validationCode":"if let Some(TokenTree::Delimited(..)) = iter.peek() {\n    // safe to descend into delimited group\n} else if let Some(TokenTree::Token(t, _)) = iter.peek() {\n    if t.kind.is_delim() {\n        // malformed: delim token instead of Delimited; skip or report\n    }\n}","typeGuard":"fn is_delimited_tt(tt: &AttrTokenTree) -> bool {\n    matches!(tt, AttrTokenTree::Delimited(..))\n}","tryCatchPattern":null,"preventionTips":["The panic indicates a stream that did not round-trip through `Delimited` reconstruction — treat it as corrupt input.","Before consuming a `MetaItem`, assert the open token is a `TokenTree::Delimited`.","When constructing `AttrTokenStream`s programmatically, always wrap groups in `AttrTokenTree::Delimited`, never bare delim tokens."],"tags":["rustc","internals","attr-tokenstream","attributes","invariant"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}