From 5c9f806d7860a281346743b31529230d5480deef Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Fri, 29 Sep 2017 23:50:34 -0700 Subject: [PATCH] code suggestion for unused-parentheses lint Resolves #42892. --- src/librustc_lint/unused.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index b97920dd18b77..c51d5d3f1e722 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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; @@ -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(); } } }