@@ -128,45 +128,43 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
128
128
self . block_indent = self . block_indent . block_indent ( self . config ) ;
129
129
self . push_str ( "{" ) ;
130
130
131
- if self . config . remove_blank_lines_at_start_or_end_of_block ( ) {
132
- if let Some ( first_stmt) = b. stmts . first ( ) {
133
- let attr_lo = inner_attrs
134
- . and_then ( |attrs| inner_attributes ( attrs) . first ( ) . map ( |attr| attr. span . lo ( ) ) )
135
- . or_else ( || {
136
- // Attributes for an item in a statement position
137
- // do not belong to the statement. (rust-lang/rust#34459)
138
- if let ast:: StmtKind :: Item ( ref item) = first_stmt. node {
139
- item. attrs . first ( )
140
- } else {
141
- first_stmt. attrs ( ) . first ( )
142
- } . and_then ( |attr| {
143
- // Some stmts can have embedded attributes.
144
- // e.g. `match { #![attr] ... }`
145
- let attr_lo = attr. span . lo ( ) ;
146
- if attr_lo < first_stmt. span . lo ( ) {
147
- Some ( attr_lo)
148
- } else {
149
- None
150
- }
151
- } )
152
- } ) ;
153
-
154
- let snippet = self . snippet ( mk_sp (
155
- self . last_pos ,
156
- attr_lo. unwrap_or_else ( || first_stmt. span . lo ( ) ) ,
157
- ) ) ;
158
- let len = CommentCodeSlices :: new ( snippet)
159
- . nth ( 0 )
160
- . and_then ( |( kind, _, s) | {
161
- if kind == CodeCharKind :: Normal {
162
- s. rfind ( '\n' )
131
+ if let Some ( first_stmt) = b. stmts . first ( ) {
132
+ let attr_lo = inner_attrs
133
+ . and_then ( |attrs| inner_attributes ( attrs) . first ( ) . map ( |attr| attr. span . lo ( ) ) )
134
+ . or_else ( || {
135
+ // Attributes for an item in a statement position
136
+ // do not belong to the statement. (rust-lang/rust#34459)
137
+ if let ast:: StmtKind :: Item ( ref item) = first_stmt. node {
138
+ item. attrs . first ( )
139
+ } else {
140
+ first_stmt. attrs ( ) . first ( )
141
+ } . and_then ( |attr| {
142
+ // Some stmts can have embedded attributes.
143
+ // e.g. `match { #![attr] ... }`
144
+ let attr_lo = attr. span . lo ( ) ;
145
+ if attr_lo < first_stmt. span . lo ( ) {
146
+ Some ( attr_lo)
163
147
} else {
164
148
None
165
149
}
166
- } ) ;
167
- if let Some ( len) = len {
168
- self . last_pos = self . last_pos + BytePos :: from_usize ( len) ;
169
- }
150
+ } )
151
+ } ) ;
152
+
153
+ let snippet = self . snippet ( mk_sp (
154
+ self . last_pos ,
155
+ attr_lo. unwrap_or_else ( || first_stmt. span . lo ( ) ) ,
156
+ ) ) ;
157
+ let len = CommentCodeSlices :: new ( snippet)
158
+ . nth ( 0 )
159
+ . and_then ( |( kind, _, s) | {
160
+ if kind == CodeCharKind :: Normal {
161
+ s. rfind ( '\n' )
162
+ } else {
163
+ None
164
+ }
165
+ } ) ;
166
+ if let Some ( len) = len {
167
+ self . last_pos = self . last_pos + BytePos :: from_usize ( len) ;
170
168
}
171
169
}
172
170
@@ -195,24 +193,22 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
195
193
}
196
194
197
195
let mut remove_len = BytePos ( 0 ) ;
198
- if self . config . remove_blank_lines_at_start_or_end_of_block ( ) {
199
- if let Some ( stmt) = b. stmts . last ( ) {
200
- let snippet = self . snippet ( mk_sp (
201
- stmt. span . hi ( ) ,
202
- source ! ( self , b. span) . hi ( ) - brace_compensation,
203
- ) ) ;
204
- let len = CommentCodeSlices :: new ( snippet)
205
- . last ( )
206
- . and_then ( |( kind, _, s) | {
207
- if kind == CodeCharKind :: Normal && s. trim ( ) . is_empty ( ) {
208
- Some ( s. len ( ) )
209
- } else {
210
- None
211
- }
212
- } ) ;
213
- if let Some ( len) = len {
214
- remove_len = BytePos :: from_usize ( len) ;
215
- }
196
+ if let Some ( stmt) = b. stmts . last ( ) {
197
+ let snippet = self . snippet ( mk_sp (
198
+ stmt. span . hi ( ) ,
199
+ source ! ( self , b. span) . hi ( ) - brace_compensation,
200
+ ) ) ;
201
+ let len = CommentCodeSlices :: new ( snippet)
202
+ . last ( )
203
+ . and_then ( |( kind, _, s) | {
204
+ if kind == CodeCharKind :: Normal && s. trim ( ) . is_empty ( ) {
205
+ Some ( s. len ( ) )
206
+ } else {
207
+ None
208
+ }
209
+ } ) ;
210
+ if let Some ( len) = len {
211
+ remove_len = BytePos :: from_usize ( len) ;
216
212
}
217
213
}
218
214
0 commit comments