{"record":{"id":"96c21cf7d5a0149c","repo":"BoundaryML/baml","slug":"encountered-impossible-doc-comment-during-parsing","errorCode":null,"errorMessage":"Encountered impossible doc comment during parsing: {:?}, {:?}","messagePattern":"Encountered impossible doc comment during parsing: (.+?), (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/ast/src/parser/parse_comments.rs","lineNumber":60,"sourceCode":"            _ => parsing_catch_all(current, \"trailing comment\", diagnostics),\n        }\n    }\n\n    if lines.is_empty() {\n        None\n    } else {\n        Some(Comment {\n            text: lines.join(\"\\n\"),\n        })\n    }\n}\n\npub(crate) fn parse_doc_comment(token: Pair<'_>) -> &str {\n    let child = token.into_inner().next().unwrap();\n    match child.as_rule() {\n        Rule::doc_content => child.as_str().trim_start(),\n        Rule::doc_comment => parse_doc_comment(child),\n        x => unreachable!(\n            \"Encountered impossible doc comment during parsing: {:?}, {:?}\",\n            x,\n            child.tokens()\n        ),\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":67,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/ast/src/parser/parse_comments.rs#L42-L67","documentation":"parse_doc_comment unwraps the first child of a doc-comment token and accepts only Rule::doc_content or nested Rule::doc_comment; anything else triggers unreachable!('Encountered impossible doc comment...'). This is a parser invariant: the pest grammar should only produce those two shapes inside doc comments.","triggerScenarios":"Calling parse_doc_comment (directly or via parse_comment_block/parse_trailing_comment) with a doc_comment pair whose child rule is neither doc_content nor doc_comment — grammar/code desync or malformed token stream.","commonSituations":"Custom or mismatched builds of the ast crate where the comment grammar rules were renamed/added; fuzzed or hand-crafted parse trees.","solutions":["Rebuild with grammar and parser code from the same crate version.","Check the debug payload ({:?} of the rule and tokens) to identify the unexpected rule and update parse_doc_comment's match.","Report the input snippet upstream if it occurs on a stock release."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"let child = token.clone().into_inner().next();\nlet ok = matches!(\n    child.as_ref().map(|c| c.as_rule()),\n    Some(Rule::doc_content) | Some(Rule::doc_comment)\n);\nif !ok {\n    eprintln!(\"unexpected doc comment shape; skipping\");\n}","typeGuard":"fn is_valid_doc_comment(token: &Pair<Rule>) -> bool {\n    matches!(\n        token.clone().into_inner().next().map(|c| c.as_rule()),\n        Some(Rule::doc_content) | Some(Rule::doc_comment)\n    )\n}","tryCatchPattern":"let r = std::panic::catch_unwind(|| parse_doc_comment(token.clone()));\nif r.is_err() {\n    return Err(anyhow!(\"malformed doc comment\"));\n}","preventionTips":["Keep grammar and parser code in the same commit/version.","Extend parse_doc_comment's match arms whenever comment grammar rules change.","Add unit tests for /// and // comment parsing after grammar edits."],"tags":["rust","parser","panic","doc-comments","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}