@@ -6,8 +6,8 @@ use rustc_middle::ty::TyCtxt;
6
6
use rustc_span:: def_id:: DefId ;
7
7
use rustc_span:: symbol:: { kw, sym, Symbol } ;
8
8
use rustc_span:: { InnerSpan , Span , DUMMY_SP } ;
9
+ use std:: mem;
9
10
use std:: ops:: Range ;
10
- use std:: { cmp, mem} ;
11
11
12
12
#[ derive( Clone , Copy , PartialEq , Eq , Debug ) ]
13
13
pub enum DocFragmentKind {
@@ -129,17 +129,20 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
129
129
let Some ( min_indent) = docs
130
130
. iter ( )
131
131
. map ( |fragment| {
132
- fragment. doc . as_str ( ) . lines ( ) . fold ( usize:: MAX , |min_indent, line| {
133
- if line. chars ( ) . all ( |c| c. is_whitespace ( ) ) {
134
- min_indent
135
- } else {
132
+ fragment
133
+ . doc
134
+ . as_str ( )
135
+ . lines ( )
136
+ . filter ( |line| line. chars ( ) . any ( |c| !c. is_whitespace ( ) ) )
137
+ . map ( |line| {
136
138
// Compare against either space or tab, ignoring whether they are
137
139
// mixed or not.
138
140
let whitespace = line. chars ( ) . take_while ( |c| * c == ' ' || * c == '\t' ) . count ( ) ;
139
- cmp:: min ( min_indent, whitespace)
140
- + if fragment. kind == DocFragmentKind :: SugaredDoc { 0 } else { add }
141
- }
142
- } )
141
+ whitespace
142
+ + ( if fragment. kind == DocFragmentKind :: SugaredDoc { 0 } else { add } )
143
+ } )
144
+ . min ( )
145
+ . unwrap_or ( usize:: MAX )
143
146
} )
144
147
. min ( )
145
148
else {
@@ -151,13 +154,13 @@ pub fn unindent_doc_fragments(docs: &mut [DocFragment]) {
151
154
continue ;
152
155
}
153
156
154
- let min_indent = if fragment. kind != DocFragmentKind :: SugaredDoc && min_indent > 0 {
157
+ let indent = if fragment. kind != DocFragmentKind :: SugaredDoc && min_indent > 0 {
155
158
min_indent - add
156
159
} else {
157
160
min_indent
158
161
} ;
159
162
160
- fragment. indent = min_indent ;
163
+ fragment. indent = indent ;
161
164
}
162
165
}
163
166
0 commit comments