File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ use syntax::attr;
2222use syntax:: feature_gate:: { BUILTIN_ATTRIBUTES , AttributeType } ;
2323use syntax:: symbol:: keywords;
2424use syntax:: ptr:: P ;
25+ use syntax:: print:: pprust;
2526use syntax:: util:: parser;
2627use syntax_pos:: Span ;
2728
@@ -325,9 +326,16 @@ impl UnusedParens {
325326 let necessary = struct_lit_needs_parens &&
326327 parser:: contains_exterior_struct_lit ( & inner) ;
327328 if !necessary {
328- cx. span_lint ( UNUSED_PARENS ,
329- value. span ,
330- & format ! ( "unnecessary parentheses around {}" , msg) )
329+ let span_msg = format ! ( "unnecessary parentheses around {}" , msg) ;
330+ let mut err = cx. struct_span_lint ( UNUSED_PARENS ,
331+ value. span ,
332+ & span_msg) ;
333+ let parens_removed = pprust:: expr_to_string ( value)
334+ . trim_matches ( |c| c == '(' || c == ')' ) . to_owned ( ) ;
335+ err. span_suggestion_short ( value. span ,
336+ "remove these parentheses" ,
337+ parens_removed) ;
338+ err. emit ( ) ;
331339 }
332340 }
333341 }
You can’t perform that action at this time.
0 commit comments