@@ -11,7 +11,7 @@ use rustc_front::intravisit::{Visitor, walk_expr, walk_block, walk_decl};
11
11
use std:: borrow:: Cow ;
12
12
use std:: collections:: HashMap ;
13
13
14
- use utils:: { snippet, span_lint, get_parent_expr, match_trait_method, match_type, in_external_macro, expr_block ,
14
+ use utils:: { snippet, span_lint, get_parent_expr, match_trait_method, match_type, in_external_macro,
15
15
span_help_and_lint, is_integer_literal, get_enclosing_block, span_lint_and_then, walk_ptrs_ty} ;
16
16
use utils:: { BTREEMAP_PATH , HASHMAP_PATH , LL_PATH , OPTION_PATH , RESULT_PATH , VEC_PATH } ;
17
17
@@ -241,20 +241,6 @@ impl LateLintPass for LoopsPass {
241
241
// or extract the first expression (if any) from the block
242
242
if let Some ( inner) = inner_stmt_expr. or_else ( || extract_first_expr ( block) ) {
243
243
if let ExprMatch ( ref matchexpr, ref arms, ref source) = inner. node {
244
- // collect the remaining statements below the match
245
- let mut other_stuff = block. stmts
246
- . iter ( )
247
- . skip ( 1 )
248
- . map ( |stmt| snippet ( cx, stmt. span , ".." ) )
249
- . collect :: < Vec < Cow < _ > > > ( ) ;
250
- if inner_stmt_expr. is_some ( ) {
251
- // if we have a statement which has a match,
252
- if let Some ( ref expr) = block. expr {
253
- // then collect the expression (without semicolon) below it
254
- other_stuff. push ( snippet ( cx, expr. span , ".." ) ) ;
255
- }
256
- }
257
-
258
244
// ensure "if let" compatible match structure
259
245
match * source {
260
246
MatchSource :: Normal | MatchSource :: IfLetDesugar { ..} => {
@@ -264,22 +250,20 @@ impl LateLintPass for LoopsPass {
264
250
if in_external_macro ( cx, expr. span ) {
265
251
return ;
266
252
}
267
- let loop_body = if inner_stmt_expr. is_some ( ) {
268
- // FIXME: should probably be an ellipsis
269
- // tabbing and newline is probably a bad idea, especially for large blocks
270
- Cow :: Owned ( format ! ( "{{\n {}\n }}" , other_stuff. join( "\n " ) ) )
271
- } else {
272
- expr_block ( cx, & arms[ 0 ] . body , Some ( other_stuff. join ( "\n " ) ) , ".." )
273
- } ;
253
+
254
+ // NOTE: we used to make build a body here instead of using
255
+ // ellipsis, this was removed because:
256
+ // 1) it was ugly with big bodies;
257
+ // 2) it was not indented properly;
258
+ // 3) it wasn’t very smart (see #675).
274
259
span_lint_and_then ( cx,
275
260
WHILE_LET_LOOP ,
276
261
expr. span ,
277
262
"this loop could be written as a `while let` loop" ,
278
263
|db| {
279
- let sug = format ! ( "while let {} = {} {}" ,
264
+ let sug = format ! ( "while let {} = {} {{ .. } }" ,
280
265
snippet( cx, arms[ 0 ] . pats[ 0 ] . span, ".." ) ,
281
- snippet( cx, matchexpr. span, ".." ) ,
282
- loop_body) ;
266
+ snippet( cx, matchexpr. span, ".." ) ) ;
283
267
db. span_suggestion ( expr. span , "try" , sug) ;
284
268
} ) ;
285
269
}
0 commit comments