Avoid .unwrap() when printing positions

pull/25/head
Wilfred Hughes 2021-07-25 13:00:46 +07:00
parent 6d5704aed9
commit 9c37d854d1
1 changed files with 5 additions and 7 deletions

@ -64,15 +64,13 @@ pub enum Syntax<'a> {
}
fn dbg_pos(pos: &[SingleLineSpan]) -> String {
if pos.is_empty() {
"-".into()
} else {
let start = pos.first().unwrap();
let end = pos.last().unwrap();
format!(
match pos {
[] => "-".into(),
[pos] => format!("{}:{}-{}", pos.line.0, pos.start_col, pos.end_col),
[start, .., end] => format!(
"{}:{}-{}:{}",
start.line.0, start.start_col, end.line.0, end.end_col
)
),
}
}