{"record":{"id":"920d10f5d2af6145","repo":"rust-lang/rust-analyzer","slug":"bad-kind-other","errorCode":null,"errorMessage":"bad kind {other}","messagePattern":"bad kind (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/proc-macro-api/src/legacy_protocol/msg/flat.rs","lineNumber":375,"sourceCode":"}\n\nimpl SubtreeRepr {\n    fn write(self) -> [u32; 4] {\n        let kind = match self.kind {\n            tt::DelimiterKind::Invisible => 0,\n            tt::DelimiterKind::Parenthesis => 1,\n            tt::DelimiterKind::Brace => 2,\n            tt::DelimiterKind::Bracket => 3,\n        };\n        [self.open.0, kind, self.tt[0], self.tt[1]]\n    }\n    fn read([open, kind, lo, len]: [u32; 4]) -> SubtreeRepr {\n        let kind = match kind {\n            0 => tt::DelimiterKind::Invisible,\n            1 => tt::DelimiterKind::Parenthesis,\n            2 => tt::DelimiterKind::Brace,\n            3 => tt::DelimiterKind::Bracket,\n            other => panic!(\"bad kind {other}\"),\n        };\n        SubtreeRepr { open: SpanId(open), close: SpanId(!0), kind, tt: [lo, len] }\n    }\n    fn write_with_close_span(self) -> [u32; 5] {\n        let kind = match self.kind {\n            tt::DelimiterKind::Invisible => 0,\n            tt::DelimiterKind::Parenthesis => 1,\n            tt::DelimiterKind::Brace => 2,\n            tt::DelimiterKind::Bracket => 3,\n        };\n        [self.open.0, self.close.0, kind, self.tt[0], self.tt[1]]\n    }\n    fn read_with_close_span([open, close, kind, lo, len]: [u32; 5]) -> SubtreeRepr {\n        let kind = match kind {\n            0 => tt::DelimiterKind::Invisible,\n            1 => tt::DelimiterKind::Parenthesis,\n            2 => tt::DelimiterKind::Brace,\n            3 => tt::DelimiterKind::Bracket,","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/proc-macro-api/src/legacy_protocol/msg/flat.rs#L357-L393","documentation":"When decoding a flattened token stream over the legacy proc-macro protocol, `SubtreeRepr::read` maps a u32 tag back to a `tt::DelimiterKind`. A value outside 0..=3 is unrecoverable protocol corruption, so the decoder panics with `bad kind {other}`.","triggerScenarios":"`SubtreeRepr::read` receives a `kind` field other than 0 (Invisible), 1 (Parenthesis), 2 (Brace), or 3 (Bracket) from a serialized 4-word subtree representation.","commonSituations":"Talking to a proc-macro server built from mismatched rust-analyzer versions whose encoding of delimiter kinds diverged; corrupted or hand-crafted flat token buffers; endianness or offset bugs when reading the flat representation.","solutions":["Ensure the proc-macro server binary and rust-analyzer use the same version / same legacy protocol encoding","Check the write side (`write`/`write_with_close_span`) emits only tags 0..=3","Validate the flat buffer before decoding, or upgrade both sides to the current (non-legacy) protocol"],"exampleFix":"// before (encode)\nlet kind = if d.kind == tt::DelimiterKind::Invisible { 4 } else { ... };\n// after\nlet kind = match d.kind {\n    tt::DelimiterKind::Invisible => 0,\n    tt::DelimiterKind::Parenthesis => 1,\n    tt::DelimiterKind::Brace => 2,\n    tt::DelimiterKind::Bracket => 3,\n};","handlingStrategy":"validation","validationCode":"fn valid_kind_tag(tag: u32) -> bool { tag <= 3 }","typeGuard":"fn is_known_delimiter_kind(tag: u32) -> bool {\n    matches!(tag, 0..=3)\n}","tryCatchPattern":null,"preventionTips":["Pin proc-macro server and rust-analyzer to the same version","Never hand-construct flat protocol buffers; use the writer functions","Validate tag values (0..=3) before decoding buffers","Prefer the current protocol over the legacy flat one"],"tags":["rust","proc-macro","protocol-decoding","panic"],"backgroundTag":"protocol-encoding-mismatch","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"}