Skip to content

Commit

Permalink
code suggestion for unused-parentheses lint
Browse files Browse the repository at this point in the history
Resolves #42892.
  • Loading branch information
zackmdavis committed Sep 30, 2017
1 parent f2c5acd commit 5c9f806
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/librustc_lint/unused.rs
Expand Up @@ -22,6 +22,7 @@ use syntax::attr;
use syntax::feature_gate::{BUILTIN_ATTRIBUTES, AttributeType};
use syntax::symbol::keywords;
use syntax::ptr::P;
use syntax::print::pprust;
use syntax::util::parser;
use syntax_pos::Span;

Expand Down Expand Up @@ -325,9 +326,16 @@ impl UnusedParens {
let necessary = struct_lit_needs_parens &&
parser::contains_exterior_struct_lit(&inner);
if !necessary {
cx.span_lint(UNUSED_PARENS,
value.span,
&format!("unnecessary parentheses around {}", msg))
let span_msg = format!("unnecessary parentheses around {}", msg);
let mut err = cx.struct_span_lint(UNUSED_PARENS,
value.span,
&span_msg);
let parens_removed = pprust::expr_to_string(value)
.trim_matches(|c| c == '(' || c == ')').to_owned();
err.span_suggestion_short(value.span,
"remove these parentheses",
parens_removed);
err.emit();
}
}
}
Expand Down

0 comments on commit 5c9f806

Please sign in to comment.