highlighter: Eagerly panic when highlight ranges are out of order

The errors were collected into the string but `errors` was never read.
Instead of collecting errors I think it's better for the sake of
debugging to panic eagerly.
This commit is contained in:
Michael Davis
2025-06-14 13:03:50 -04:00
parent 987bba27f9
commit 6128c5a31d

View File

@@ -206,26 +206,23 @@ pub fn highlighter_fixture(
wln!(res, "{ident}{line}")
}
}
let mut errors = String::new();
while pos < end as u32 {
let (event, new_highlights) = highlighter.advance();
if event == HighlightEvent::Refresh {
highlight_stack.clear();
}
highlight_stack.extend(new_highlights.map(&get_highlight_name));
let mut start = pos;
let start = pos;
pos = highlighter.next_event_offset();
if pos == u32::MAX {
pos = src.len_bytes() as u32
}
if pos <= start {
wln!(
errors,
"INVALID HIGHLIGHT RANGE: {start}..{pos} {:?} {:?}",
panic!(
"INVALID HIGHLIGHT RANGE: {start}..{pos} '{}' {:?}",
src.byte_slice(pos as usize..start as usize),
highlight_stack
);
start = pos;
}
while start >= line_end {