Skip to content

Commit 6128c5a

Browse files
committed
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.
1 parent 987bba2 commit 6128c5a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

highlighter/src/fixtures.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,23 @@ pub fn highlighter_fixture(
206206
wln!(res, "{ident}{line}")
207207
}
208208
}
209-
let mut errors = String::new();
210209
while pos < end as u32 {
211210
let (event, new_highlights) = highlighter.advance();
212211
if event == HighlightEvent::Refresh {
213212
highlight_stack.clear();
214213
}
215214
highlight_stack.extend(new_highlights.map(&get_highlight_name));
216-
let mut start = pos;
215+
let start = pos;
217216
pos = highlighter.next_event_offset();
218217
if pos == u32::MAX {
219218
pos = src.len_bytes() as u32
220219
}
221220
if pos <= start {
222-
wln!(
223-
errors,
224-
"INVALID HIGHLIGHT RANGE: {start}..{pos} {:?} {:?}",
221+
panic!(
222+
"INVALID HIGHLIGHT RANGE: {start}..{pos} '{}' {:?}",
225223
src.byte_slice(pos as usize..start as usize),
226224
highlight_stack
227225
);
228-
start = pos;
229226
}
230227

231228
while start >= line_end {

0 commit comments

Comments
 (0)