{"id":"376bd288243e3007","repo":"rust-lang/rust","slug":"no-error-found-for-supposedly-invalid-raw-string-l","errorCode":null,"errorMessage":"no error found for supposedly invalid raw string literal","messagePattern":"no error found for supposedly invalid raw string literal","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_parse/src/lexer/mod.rs","lineNumber":951,"sourceCode":"        &self.src[self.src_index(start)..self.src_index(end)]\n    }\n\n    /// Slice of the source text spanning from `start` until the end\n    fn str_from_to_end(&self, start: BytePos) -> &'src str {\n        &self.src[self.src_index(start)..]\n    }\n\n    fn report_raw_str_error(&self, start: BytePos, prefix_len: u32) -> ! {\n        match rustc_lexer::validate_raw_str(self.str_from(start), prefix_len) {\n            Err(RawStrError::InvalidStarter { bad_char }) => {\n                self.report_non_started_raw_string(start, bad_char)\n            }\n            Err(RawStrError::NoTerminator { expected, found, possible_terminator_offset }) => self\n                .report_unterminated_raw_string(start, expected, possible_terminator_offset, found),\n            Err(RawStrError::TooManyDelimiters { found }) => {\n                self.report_too_many_hashes(start, found)\n            }\n            Ok(()) => panic!(\"no error found for supposedly invalid raw string literal\"),\n        }\n    }\n\n    fn report_non_started_raw_string(&self, start: BytePos, bad_char: char) -> ! {\n        self.dcx()\n            .struct_span_fatal(\n                self.mk_sp(start, self.pos),\n                format!(\n                    \"found invalid character; only `#` is allowed in raw string delimitation: {}\",\n                    escaped_char(bad_char)\n                ),\n            )\n            .emit()\n    }\n\n    fn report_unterminated_raw_string(\n        &self,\n        start: BytePos,","sourceCodeStart":933,"sourceCodeEnd":969,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_parse/src/lexer/mod.rs#L933-L969","documentation":"Internal compiler error in `report_raw_str_error`. This function is only entered once the lexer has already decided a raw string literal is malformed, so `rustc_lexer::validate_raw_str` is contractually expected to return an `Err` describing the problem. If validation instead returns `Ok(())`, the lexer's high-level parsing and the validator disagree, and the compiler panics instead of emitting a potentially incorrect diagnostic.","triggerScenarios":"Lexing a raw string literal (`r\"...\"`, `br\"...\"`, `r#\"...\"#`) whose delimiter/hash-count state the lexer flagged as invalid, but which `validate_raw_str` then classifies as well-formed.","commonSituations":"Edge cases in hash-delimiter counting or partially-terminated raw strings, typically surfaced by fuzzing, machine-generated source, or a regression after lexer refactors.","solutions":["Capture the exact raw-string literal that triggers the panic into a minimal standalone file","Report it as a rust-lang/rust ICE with the literal and `RUST_BACKTRACE=1` output","Bisect nightly toolchains to find the introducing commit if it is a recent regression","Rewrite the offending literal as a normal `\"...\"` string or with a different hash count as a temporary workaround"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn raw_string_is_well_formed(src: &str) -> bool {\n    // r#...# with matching hash counts and a closing delimiter\n    let bytes = src.as_bytes();\n    if bytes.len() < 2 || bytes[0] != b'r' { return false; }\n    let mut i = 1; let mut hashes = 0;\n    while i < bytes.len() && bytes[i] == b'#' { hashes += 1; i += 1; }\n    if i >= bytes.len() || bytes[i] != b'\"' { return false; }\n    let closer = format!('\"' + &\"#\".repeat(hashes));\n    src[i+1..].ends_with(&closer)\n}\nif !raw_string_is_well_formed(literal_src) { return Ok(()); }","typeGuard":null,"tryCatchPattern":"use std::panic;\nlet _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {\n    lexer.report_invalid_raw_string(span)\n}));","preventionTips":["Before invoking the 'invalid raw string' reporting path, confirm the literal actually fails raw-string grammar (matching hash counts, present closing quote).","Validate hash-balance of r#...# forms in a pre-pass so you never claim a literal is invalid when it is well-formed.","Treat a missing closing delimiter as the canonical invalid-raw-string case; other shapes may satisfy the lexer and trip its assertion.","Never reconstruct raw strings span-by-span; re-lex from the original source so delimiters stay consistent."],"tags":["compiler-ice","lexer","raw-strings"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}