@@ -72,23 +72,7 @@ impl<'a> fmt::Debug for DisplayList<'a> {
72
72
73
73
impl < ' a > Display for DisplayList < ' a > {
74
74
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
75
- let max_lineno = self . body . iter ( ) . fold ( None , |max, set| {
76
- set. display_lines . iter ( ) . fold ( max, |max, line| match line {
77
- DisplayLine :: Source { lineno, .. } => match ( max, lineno) {
78
- ( Some ( max) , Some ( lineno) ) => Some ( cmp:: max ( max, * lineno) ) ,
79
- ( Some ( max) , None ) => Some ( max) ,
80
- ( None , Some ( lineno) ) => Some ( * lineno) ,
81
- ( None , None ) => None ,
82
- } ,
83
- _ => max,
84
- } )
85
- } ) ;
86
- let lineno_width = match max_lineno {
87
- None => 0 ,
88
- Some ( 0 ) => 1 ,
89
- Some ( _max) if self . anonymized_line_numbers => ANONYMIZED_LINE_NUM . len ( ) ,
90
- Some ( max) => ( max as f64 ) . log10 ( ) . floor ( ) as usize + 1 ,
91
- } ;
75
+ let lineno_width = self . get_lineno_width ( ) ;
92
76
93
77
let multiline_depth = self . body . iter ( ) . fold ( 0 , |max, set| {
94
78
set. display_lines . iter ( ) . fold ( max, |max2, line| match line {
@@ -152,6 +136,27 @@ impl<'a> DisplayList<'a> {
152
136
}
153
137
Ok ( ( ) )
154
138
}
139
+
140
+ fn get_lineno_width ( & self ) -> usize {
141
+ let max_lineno = self . body . iter ( ) . fold ( None , |max, set| {
142
+ set. display_lines . iter ( ) . fold ( max, |max, line| match line {
143
+ DisplayLine :: Source { lineno, .. } => match ( max, lineno) {
144
+ ( Some ( max) , Some ( lineno) ) => Some ( cmp:: max ( max, * lineno) ) ,
145
+ ( Some ( max) , None ) => Some ( max) ,
146
+ ( None , Some ( lineno) ) => Some ( * lineno) ,
147
+ ( None , None ) => None ,
148
+ } ,
149
+ _ => max,
150
+ } )
151
+ } ) ;
152
+ let lineno_width = match max_lineno {
153
+ None => 0 ,
154
+ Some ( 0 ) => 1 ,
155
+ Some ( _max) if self . anonymized_line_numbers => ANONYMIZED_LINE_NUM . len ( ) ,
156
+ Some ( max) => ( max as f64 ) . log10 ( ) . floor ( ) as usize + 1 ,
157
+ } ;
158
+ lineno_width
159
+ }
155
160
}
156
161
157
162
#[ derive( Debug , PartialEq ) ]
0 commit comments