@@ -22,6 +22,7 @@ use syntax::attr;
22
22
use syntax:: feature_gate:: { BUILTIN_ATTRIBUTES , AttributeType } ;
23
23
use syntax:: symbol:: keywords;
24
24
use syntax:: ptr:: P ;
25
+ use syntax:: util:: parser;
25
26
use syntax_pos:: Span ;
26
27
27
28
use rustc_back:: slice;
@@ -313,47 +314,14 @@ impl UnusedParens {
313
314
msg : & str ,
314
315
struct_lit_needs_parens : bool ) {
315
316
if let ast:: ExprKind :: Paren ( ref inner) = value. node {
316
- let necessary = struct_lit_needs_parens && contains_exterior_struct_lit ( & inner) ;
317
+ let necessary = struct_lit_needs_parens &&
318
+ parser:: contains_exterior_struct_lit ( & inner) ;
317
319
if !necessary {
318
320
cx. span_lint ( UNUSED_PARENS ,
319
321
value. span ,
320
322
& format ! ( "unnecessary parentheses around {}" , msg) )
321
323
}
322
324
}
323
-
324
- /// Expressions that syntactically contain an "exterior" struct
325
- /// literal i.e. not surrounded by any parens or other
326
- /// delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo
327
- /// == X { y: 1 }` and `X { y: 1 } == foo` all do, but `(X {
328
- /// y: 1 }) == foo` does not.
329
- fn contains_exterior_struct_lit ( value : & ast:: Expr ) -> bool {
330
- match value. node {
331
- ast:: ExprKind :: Struct ( ..) => true ,
332
-
333
- ast:: ExprKind :: Assign ( ref lhs, ref rhs) |
334
- ast:: ExprKind :: AssignOp ( _, ref lhs, ref rhs) |
335
- ast:: ExprKind :: Binary ( _, ref lhs, ref rhs) => {
336
- // X { y: 1 } + X { y: 2 }
337
- contains_exterior_struct_lit ( & lhs) || contains_exterior_struct_lit ( & rhs)
338
- }
339
- ast:: ExprKind :: Unary ( _, ref x) |
340
- ast:: ExprKind :: Cast ( ref x, _) |
341
- ast:: ExprKind :: Type ( ref x, _) |
342
- ast:: ExprKind :: Field ( ref x, _) |
343
- ast:: ExprKind :: TupField ( ref x, _) |
344
- ast:: ExprKind :: Index ( ref x, _) => {
345
- // &X { y: 1 }, X { y: 1 }.y
346
- contains_exterior_struct_lit ( & x)
347
- }
348
-
349
- ast:: ExprKind :: MethodCall ( .., ref exprs) => {
350
- // X { y: 1 }.bar(...)
351
- contains_exterior_struct_lit ( & exprs[ 0 ] )
352
- }
353
-
354
- _ => false ,
355
- }
356
- }
357
325
}
358
326
}
359
327
0 commit comments