diff --git a/src/renderer/display_list.rs b/src/renderer/display_list.rs index 516adc5..4b44065 100644 --- a/src/renderer/display_list.rs +++ b/src/renderer/display_list.rs @@ -72,12 +72,7 @@ impl<'a> fmt::Debug for DisplayList<'a> { impl<'a> Display for DisplayList<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let max_lineno = self.body.iter().fold(None, |max, set| { - set.display_lines.iter().fold(max, |max, line| match line { - DisplayLine::Source { lineno, .. } => std::cmp::max(max, *lineno), - _ => max, - }) - }); + let max_lineno = get_max_lineno(&self.body); let lineno_width = match max_lineno { None => 0, Some(_max) if self.anonymized_line_numbers => ANONYMIZED_LINE_NUM.len(), @@ -149,6 +144,16 @@ impl<'a> DisplayList<'a> { } } +fn get_max_lineno(body: &Vec>) -> Option { + let max_lineno = body.iter().fold(None, |max, set| { + set.display_lines.iter().fold(max, |max, line| match line { + DisplayLine::Source { lineno, .. } => std::cmp::max(max, *lineno), + _ => max, + }) + }); + max_lineno +} + #[derive(Debug, PartialEq)] pub(crate) struct DisplaySet<'a> { pub(crate) display_lines: Vec>,