Skip to content

Commit 5c9f806

Browse files
committed
code suggestion for unused-parentheses lint
Resolves rust-lang#42892.
1 parent f2c5acd commit 5c9f806

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/librustc_lint/unused.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use syntax::attr;
2222
use syntax::feature_gate::{BUILTIN_ATTRIBUTES, AttributeType};
2323
use syntax::symbol::keywords;
2424
use syntax::ptr::P;
25+
use syntax::print::pprust;
2526
use syntax::util::parser;
2627
use 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
}

0 commit comments

Comments
 (0)