From dc02b51382d5fea61d74624273d1d98263745243 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Thu, 9 Sep 2021 14:22:24 +0000 Subject: [PATCH] Use more accurate spans for "unused delimiter" lint --- compiler/rustc_lint/src/unused.rs | 120 +++++------ .../issues/issue-54752-async-block.stderr | 7 +- .../ui/const-generics/unused_braces.stderr | 7 +- .../ui/lint/lint-unnecessary-parens.stderr | 135 +++++++++++-- src/test/ui/lint/suggestions.stderr | 7 +- .../issue-54538-unused-parens-lint.stderr | 191 +++++++++++++++--- ...ssue-74883-unused-paren-baren-yield.stderr | 46 ++++- src/test/ui/lint/unused_braces.stderr | 38 +++- src/test/ui/lint/unused_braces_borrow.stderr | 7 +- .../lint/unused_parens_json_suggestion.stderr | 9 +- ...nused_parens_remove_json_suggestion.stderr | 89 ++++++-- src/test/ui/path-lookahead.stderr | 7 +- .../try-block/try-block-unused-delims.stderr | 38 +++- 13 files changed, 551 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 7a42e8c1037ba..48b955e41ac69 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -3,7 +3,6 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext} use rustc_ast as ast; use rustc_ast::util::{classify, parser}; use rustc_ast::{ExprKind, StmtKind}; -use rustc_ast_pretty::pprust; use rustc_errors::{pluralize, Applicability}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -12,7 +11,7 @@ use rustc_middle::ty::adjustment; use rustc_middle::ty::{self, Ty}; use rustc_span::symbol::Symbol; use rustc_span::symbol::{kw, sym}; -use rustc_span::{BytePos, Span, DUMMY_SP}; +use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP}; declare_lint! { /// The `unused_must_use` lint detects unused result of a type flagged as @@ -491,77 +490,60 @@ trait UnusedDelimLint { left_pos: Option, right_pos: Option, ) { - let expr_text = if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) { - snippet - } else { - pprust::expr_to_string(value) + let spans = match value.kind { + ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => { + let start = block.stmts[0].span; + let end = block.stmts[block.stmts.len() - 1].span; + if value.span.from_expansion() || start.from_expansion() || end.from_expansion() { + ( + value.span.with_hi(value.span.lo() + BytePos(1)), + value.span.with_lo(value.span.hi() - BytePos(1)), + ) + } else { + (value.span.with_hi(start.lo()), value.span.with_lo(end.hi())) + } + } + ast::ExprKind::Paren(ref expr) => { + if value.span.from_expansion() || expr.span.from_expansion() { + ( + value.span.with_hi(value.span.lo() + BytePos(1)), + value.span.with_lo(value.span.hi() - BytePos(1)), + ) + } else { + (value.span.with_hi(expr.span.lo()), value.span.with_lo(expr.span.hi())) + } + } + _ => return, }; let keep_space = ( left_pos.map_or(false, |s| s >= value.span.lo()), right_pos.map_or(false, |s| s <= value.span.hi()), ); - self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space); + self.emit_unused_delims(cx, spans, ctx.into(), keep_space); } fn emit_unused_delims( &self, cx: &EarlyContext<'_>, - span: Span, - pattern: &str, + spans: (Span, Span), msg: &str, keep_space: (bool, bool), ) { // FIXME(flip1995): Quick and dirty fix for #70814. This should be fixed in rustdoc // properly. - if span == DUMMY_SP { + if spans.0 == DUMMY_SP || spans.1 == DUMMY_SP { return; } - cx.struct_span_lint(self.lint(), span, |lint| { + cx.struct_span_lint(self.lint(), MultiSpan::from(vec![spans.0, spans.1]), |lint| { let span_msg = format!("unnecessary {} around {}", Self::DELIM_STR, msg); let mut err = lint.build(&span_msg); - let mut ate_left_paren = false; - let mut ate_right_paren = false; - let parens_removed = pattern - .trim_matches(|c| match c { - '(' | '{' => { - if ate_left_paren { - false - } else { - ate_left_paren = true; - true - } - } - ')' | '}' => { - if ate_right_paren { - false - } else { - ate_right_paren = true; - true - } - } - _ => false, - }) - .trim(); - - let replace = { - let mut replace = if keep_space.0 { - let mut s = String::from(" "); - s.push_str(parens_removed); - s - } else { - String::from(parens_removed) - }; - - if keep_space.1 { - replace.push(' '); - } - replace - }; - + let replacement = vec![ + (spans.0, if keep_space.0 { " ".into() } else { "".into() }), + (spans.1, if keep_space.1 { " ".into() } else { "".into() }), + ]; let suggestion = format!("remove these {}", Self::DELIM_STR); - - err.span_suggestion_short(span, &suggestion, replace, Applicability::MachineApplicable); + err.multipart_suggestion(&suggestion, replacement, Applicability::MachineApplicable); err.emit(); }); } @@ -770,14 +752,15 @@ impl UnusedParens { // Otherwise proceed with linting. _ => {} } - - let pattern_text = - if let Ok(snippet) = cx.sess().source_map().span_to_snippet(value.span) { - snippet - } else { - pprust::pat_to_string(value) - }; - self.emit_unused_delims(cx, value.span, &pattern_text, "pattern", (false, false)); + let spans = if value.span.from_expansion() || inner.span.from_expansion() { + ( + value.span.with_hi(value.span.lo() + BytePos(1)), + value.span.with_lo(value.span.hi() - BytePos(1)), + ) + } else { + (value.span.with_hi(inner.span.lo()), value.span.with_lo(inner.span.hi())) + }; + self.emit_unused_delims(cx, spans, "pattern", (false, false)); } } } @@ -870,14 +853,15 @@ impl EarlyLintPass for UnusedParens { ); } _ => { - let pattern_text = - if let Ok(snippet) = cx.sess().source_map().span_to_snippet(ty.span) { - snippet - } else { - pprust::ty_to_string(ty) - }; - - self.emit_unused_delims(cx, ty.span, &pattern_text, "type", (false, false)); + let spans = if ty.span.from_expansion() || r.span.from_expansion() { + ( + ty.span.with_hi(ty.span.lo() + BytePos(1)), + ty.span.with_lo(ty.span.hi() - BytePos(1)), + ) + } else { + (ty.span.with_hi(r.span.lo()), ty.span.with_lo(r.span.hi())) + }; + self.emit_unused_delims(cx, spans, "type", (false, false)); } } } diff --git a/src/test/ui/async-await/issues/issue-54752-async-block.stderr b/src/test/ui/async-await/issues/issue-54752-async-block.stderr index e39a049e2d304..0aea56ddb702b 100644 --- a/src/test/ui/async-await/issues/issue-54752-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-54752-async-block.stderr @@ -2,9 +2,14 @@ warning: unnecessary parentheses around assigned value --> $DIR/issue-54752-async-block.rs:6:22 | LL | fn main() { let _a = (async { }); } - | ^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ | = note: `#[warn(unused_parens)]` on by default +help: remove these parentheses + | +LL - fn main() { let _a = (async { }); } +LL + fn main() { let _a = async { }; } + | warning: 1 warning emitted diff --git a/src/test/ui/const-generics/unused_braces.stderr b/src/test/ui/const-generics/unused_braces.stderr index 5e1bace549241..533fcabd41822 100644 --- a/src/test/ui/const-generics/unused_braces.stderr +++ b/src/test/ui/const-generics/unused_braces.stderr @@ -2,13 +2,18 @@ warning: unnecessary braces around const expression --> $DIR/unused_braces.rs:9:14 | LL | let _: A<{ 7 }>; - | ^^^^^ help: remove these braces + | ^^ ^^ | note: the lint level is defined here --> $DIR/unused_braces.rs:3:9 | LL | #![warn(unused_braces)] | ^^^^^^^^^^^^^ +help: remove these braces + | +LL - let _: A<{ 7 }>; +LL + let _: A<7>; + | warning: 1 warning emitted diff --git a/src/test/ui/lint/lint-unnecessary-parens.stderr b/src/test/ui/lint/lint-unnecessary-parens.stderr index 9eae7da90047e..1d5f9ebb5e5c5 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.stderr +++ b/src/test/ui/lint/lint-unnecessary-parens.stderr @@ -2,109 +2,210 @@ error: unnecessary parentheses around `return` value --> $DIR/lint-unnecessary-parens.rs:13:12 | LL | return (1); - | ^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/lint-unnecessary-parens.rs:3:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - return (1); +LL + return 1; + | error: unnecessary parentheses around `return` value --> $DIR/lint-unnecessary-parens.rs:16:12 | LL | return (X { y }); - | ^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - return (X { y }); +LL + return X { y }; + | error: unnecessary parentheses around type --> $DIR/lint-unnecessary-parens.rs:19:46 | LL | pub fn unused_parens_around_return_type() -> (u32) { - | ^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - pub fn unused_parens_around_return_type() -> (u32) { +LL + pub fn unused_parens_around_return_type() -> u32 { + | error: unnecessary parentheses around block return value --> $DIR/lint-unnecessary-parens.rs:25:9 | LL | (5) - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (5) +LL + 5 + | error: unnecessary parentheses around block return value --> $DIR/lint-unnecessary-parens.rs:27:5 | LL | (5) - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (5) +LL + 5 + | error: unnecessary parentheses around assigned value --> $DIR/lint-unnecessary-parens.rs:44:31 | LL | pub const CONST_ITEM: usize = (10); - | ^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - pub const CONST_ITEM: usize = (10); +LL + pub const CONST_ITEM: usize = 10; + | error: unnecessary parentheses around assigned value --> $DIR/lint-unnecessary-parens.rs:45:33 | LL | pub static STATIC_ITEM: usize = (10); - | ^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - pub static STATIC_ITEM: usize = (10); +LL + pub static STATIC_ITEM: usize = 10; + | error: unnecessary parentheses around function argument --> $DIR/lint-unnecessary-parens.rs:49:9 | LL | bar((true)); - | ^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - bar((true)); +LL + bar(true); + | error: unnecessary parentheses around `if` condition --> $DIR/lint-unnecessary-parens.rs:51:8 | LL | if (true) {} - | ^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if (true) {} +LL + if true {} + | error: unnecessary parentheses around `while` condition --> $DIR/lint-unnecessary-parens.rs:52:11 | LL | while (true) {} - | ^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while (true) {} +LL + while true {} + | error: unnecessary parentheses around `match` scrutinee expression --> $DIR/lint-unnecessary-parens.rs:53:11 | LL | match (true) { - | ^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - match (true) { +LL + match true { + | error: unnecessary parentheses around `let` scrutinee expression --> $DIR/lint-unnecessary-parens.rs:56:16 | LL | if let 1 = (1) {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let 1 = (1) {} +LL + if let 1 = 1 {} + | error: unnecessary parentheses around `let` scrutinee expression --> $DIR/lint-unnecessary-parens.rs:57:19 | LL | while let 1 = (2) {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while let 1 = (2) {} +LL + while let 1 = 2 {} + | error: unnecessary parentheses around method argument --> $DIR/lint-unnecessary-parens.rs:73:24 | LL | X { y: false }.foo((true)); - | ^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - X { y: false }.foo((true)); +LL + X { y: false }.foo(true); + | error: unnecessary parentheses around assigned value --> $DIR/lint-unnecessary-parens.rs:75:18 | LL | let mut _a = (0); - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - let mut _a = (0); +LL + let mut _a = 0; + | error: unnecessary parentheses around assigned value --> $DIR/lint-unnecessary-parens.rs:76:10 | LL | _a = (0); - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - _a = (0); +LL + _a = 0; + | error: unnecessary parentheses around assigned value --> $DIR/lint-unnecessary-parens.rs:77:11 | LL | _a += (1); - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - _a += (1); +LL + _a += 1; + | error: aborting due to 17 previous errors diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr index cad2514625588..255772ff40261 100644 --- a/src/test/ui/lint/suggestions.stderr +++ b/src/test/ui/lint/suggestions.stderr @@ -10,13 +10,18 @@ warning: unnecessary parentheses around assigned value --> $DIR/suggestions.rs:48:31 | LL | let mut registry_no = (format!("NX-{}", 74205)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/suggestions.rs:4:21 | LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let mut registry_no = (format!("NX-{}", 74205)); +LL + let mut registry_no = format!("NX-{}", 74205); + | warning: variable does not need to be mutable --> $DIR/suggestions.rs:48:13 diff --git a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr index e6d0a359c5ca7..677b96d3f32f0 100644 --- a/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr +++ b/src/test/ui/lint/unused/issue-54538-unused-parens-lint.stderr @@ -2,151 +2,294 @@ error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:16:9 | LL | let (a) = 0; - | ^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/issue-54538-unused-parens-lint.rs:13:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let (a) = 0; +LL + let a = 0; + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:17:9 | LL | for (a) in 0..1 {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - for (a) in 0..1 {} +LL + for a in 0..1 {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:18:12 | LL | if let (a) = 0 {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let (a) = 0 {} +LL + if let a = 0 {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:19:15 | LL | while let (a) = 0 {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while let (a) = 0 {} +LL + while let a = 0 {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:20:12 | LL | fn foo((a): u8) {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - fn foo((a): u8) {} +LL + fn foo(a: u8) {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:21:14 | LL | let _ = |(a): u8| 0; - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - let _ = |(a): u8| 0; +LL + let _ = |a: u8| 0; + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:49:12 | LL | if let (0 | 1) = 0 {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let (0 | 1) = 0 {} +LL + if let 0 | 1 = 0 {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:50:13 | LL | if let ((0 | 1),) = (0,) {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let ((0 | 1),) = (0,) {} +LL + if let (0 | 1,) = (0,) {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:51:13 | LL | if let [(0 | 1)] = [0] {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let [(0 | 1)] = [0] {} +LL + if let [0 | 1] = [0] {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:52:16 | LL | if let 0 | (1 | 2) = 0 {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let 0 | (1 | 2) = 0 {} +LL + if let 0 | 1 | 2 = 0 {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:54:15 | LL | if let TS((0 | 1)) = TS(0) {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let TS((0 | 1)) = TS(0) {} +LL + if let TS(0 | 1) = TS(0) {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:56:20 | LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let NS { f: (0 | 1) } = (NS { f: 0 }) {} +LL + if let NS { f: 0 | 1 } = (NS { f: 0 }) {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:66:9 | LL | (_) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (_) => {} +LL + _ => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:67:9 | LL | (y) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (y) => {} +LL + y => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:68:9 | LL | (ref r) => {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (ref r) => {} +LL + ref r => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:69:9 | LL | (e @ 1...2) => {} - | ^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (e @ 1...2) => {} +LL + e @ 1...2 => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:75:9 | LL | (e @ &(1...2)) => {} - | ^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (e @ &(1...2)) => {} +LL + e @ &(1...2) => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:76:10 | LL | &(_) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - &(_) => {} +LL + &_ => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:87:9 | LL | (_) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (_) => {} +LL + _ => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:88:9 | LL | (y) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (y) => {} +LL + y => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:89:9 | LL | (ref r) => {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (ref r) => {} +LL + ref r => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:90:9 | LL | (e @ 1..=2) => {} - | ^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (e @ 1..=2) => {} +LL + e @ 1..=2 => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:96:9 | LL | (e @ &(1..=2)) => {} - | ^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - (e @ &(1..=2)) => {} +LL + e @ &(1..=2) => {} + | error: unnecessary parentheses around pattern --> $DIR/issue-54538-unused-parens-lint.rs:97:10 | LL | &(_) => {} - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - &(_) => {} +LL + &_ => {} + | error: aborting due to 24 previous errors diff --git a/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr index 3f6260dc6e19e..a715093df4c32 100644 --- a/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr +++ b/src/test/ui/lint/unused/issue-74883-unused-paren-baren-yield.stderr @@ -2,49 +2,83 @@ error: unnecessary parentheses around `let` scrutinee expression --> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29 | LL | while let Some(_) = ({yield}) {} - | ^^^^^^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:24 | LL | #![deny(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - while let Some(_) = ({yield}) {} +LL + while let Some(_) = {yield} {} + | error: unnecessary parentheses around `let` scrutinee expression --> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29 | LL | while let Some(_) = ((yield)) {} - | ^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while let Some(_) = ((yield)) {} +LL + while let Some(_) = (yield) {} + | error: unnecessary braces around block return value --> $DIR/issue-74883-unused-paren-baren-yield.rs:16:10 | LL | {{yield}}; - | ^^^^^^^ help: remove these braces + | ^ ^ | note: the lint level is defined here --> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9 | LL | #![deny(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ +help: remove these braces + | +LL - {{yield}}; +LL + {yield}; + | error: unnecessary parentheses around block return value --> $DIR/issue-74883-unused-paren-baren-yield.rs:17:10 | LL | {( yield )}; - | ^^^^^^^^^ help: remove these parentheses + | ^^ ^^ + | +help: remove these parentheses + | +LL - {( yield )}; +LL + {yield}; + | error: unnecessary parentheses around block return value --> $DIR/issue-74883-unused-paren-baren-yield.rs:18:30 | LL | while let Some(_) = {(yield)} {} - | ^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while let Some(_) = {(yield)} {} +LL + while let Some(_) = {yield} {} + | error: unnecessary braces around block return value --> $DIR/issue-74883-unused-paren-baren-yield.rs:19:30 | LL | while let Some(_) = {{yield}} {} - | ^^^^^^^ help: remove these braces + | ^ ^ + | +help: remove these braces + | +LL - while let Some(_) = {{yield}} {} +LL + while let Some(_) = {yield} {} + | error: aborting due to 6 previous errors diff --git a/src/test/ui/lint/unused_braces.stderr b/src/test/ui/lint/unused_braces.stderr index 8fa5dfde61db0..7d6fef00ac1a4 100644 --- a/src/test/ui/lint/unused_braces.stderr +++ b/src/test/ui/lint/unused_braces.stderr @@ -2,43 +2,71 @@ warning: unnecessary parentheses around assigned value --> $DIR/unused_braces.rs:10:13 | LL | let _ = (7); - | ^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/unused_braces.rs:4:24 | LL | #![warn(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let _ = (7); +LL + let _ = 7; + | warning: unnecessary braces around `if` condition --> $DIR/unused_braces.rs:26:8 | LL | if { true } { - | ^^^^^^^^ help: remove these braces + | ^^ ^^ | note: the lint level is defined here --> $DIR/unused_braces.rs:4:9 | LL | #![warn(unused_braces, unused_parens)] | ^^^^^^^^^^^^^ +help: remove these braces + | +LL - if { true } { +LL + if true { + | warning: unnecessary braces around `while` condition --> $DIR/unused_braces.rs:30:11 | LL | while { false } { - | ^^^^^^^^^ help: remove these braces + | ^^ ^^ + | +help: remove these braces + | +LL - while { false } { +LL + while false { + | warning: unnecessary braces around const expression --> $DIR/unused_braces.rs:34:17 | LL | let _: [u8; { 3 }]; - | ^^^^^ help: remove these braces + | ^^ ^^ + | +help: remove these braces + | +LL - let _: [u8; { 3 }]; +LL + let _: [u8; 3]; + | warning: unnecessary braces around function argument --> $DIR/unused_braces.rs:37:13 | LL | consume({ 7 }); - | ^^^^^ help: remove these braces + | ^^ ^^ + | +help: remove these braces + | +LL - consume({ 7 }); +LL + consume(7); + | warning: 5 warnings emitted diff --git a/src/test/ui/lint/unused_braces_borrow.stderr b/src/test/ui/lint/unused_braces_borrow.stderr index f018c46fcd3c6..5a5326cab3b1d 100644 --- a/src/test/ui/lint/unused_braces_borrow.stderr +++ b/src/test/ui/lint/unused_braces_borrow.stderr @@ -2,13 +2,18 @@ warning: unnecessary braces around function argument --> $DIR/unused_braces_borrow.rs:24:13 | LL | consume({ a.b }); - | ^^^^^^^ help: remove these braces + | ^^ ^^ | note: the lint level is defined here --> $DIR/unused_braces_borrow.rs:4:9 | LL | #![warn(unused_braces)] | ^^^^^^^^^^^^^ +help: remove these braces + | +LL - consume({ a.b }); +LL + consume(a.b); + | warning: 1 warning emitted diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr index 09f0fc90032dc..498c25d2e1c44 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr @@ -1,14 +1,19 @@ -{"message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":596,"byte_end":609,"line_start":16,"line_end":16,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3)); +{"message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":596,"byte_end":597,"line_start":16,"line_end":16,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3)); --> $DIR/unused_parens_json_suggestion.rs:16:14 | LL | let _a = (1 / (2 + 3)); - | ^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/unused_parens_json_suggestion.rs:10:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let _a = (1 / (2 + 3)); +LL + let _a = 1 / (2 + 3); + | "} {"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error diff --git a/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr index 5fb67fd7c95a3..08291b10fcc20 100644 --- a/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr +++ b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr @@ -1,70 +1,123 @@ -{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":500,"byte_end":504,"line_start":17,"line_end":17,"column_start":8,"column_end":12,"is_primary":true,"text":[{"text":" if (_b) { +{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":500,"byte_end":501,"line_start":17,"line_end":17,"column_start":8,"column_end":9,"is_primary":true,"text":[{"text":" if (_b) { --> $DIR/unused_parens_remove_json_suggestion.rs:17:8 | LL | if (_b) { - | ^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/unused_parens_remove_json_suggestion.rs:10:9 | LL | #![deny(unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - if (_b) { +LL + if _b { + | "} -{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":631,"byte_end":634,"line_start":28,"line_end":28,"column_start":7,"column_end":10,"is_primary":true,"text":[{"text":" if(c) { +{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":631,"byte_end":632,"line_start":28,"line_end":28,"column_start":7,"column_end":8,"is_primary":true,"text":[{"text":" if(c) { --> $DIR/unused_parens_remove_json_suggestion.rs:28:7 | LL | if(c) { - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if(c) { +LL + if c { + | "} -{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":711,"byte_end":714,"line_start":32,"line_end":32,"column_start":8,"column_end":11,"is_primary":true,"text":[{"text":" if (c){ +{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":711,"byte_end":712,"line_start":32,"line_end":32,"column_start":8,"column_end":9,"is_primary":true,"text":[{"text":" if (c){ --> $DIR/unused_parens_remove_json_suggestion.rs:32:8 | LL | if (c){ - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if (c){ +LL + if c { + | "} -{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":808,"line_start":36,"line_end":36,"column_start":11,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":26}],"label":null,"suggested_replacement":"false && true ","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around `while` condition +{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":794,"line_start":36,"line_end":36,"column_start":11,"column_end":12,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":12}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":807,"byte_end":808,"line_start":36,"line_end":36,"column_start":25,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":25,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":793,"byte_end":794,"line_start":36,"line_end":36,"column_start":11,"column_end":12,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":11,"highlight_end":12}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null},{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":807,"byte_end":808,"line_start":36,"line_end":36,"column_start":25,"column_end":26,"is_primary":true,"text":[{"text":" while (false && true){","highlight_start":25,"highlight_end":26}],"label":null,"suggested_replacement":" ","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around `while` condition --> $DIR/unused_parens_remove_json_suggestion.rs:36:11 | LL | while (false && true){ - | ^^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while (false && true){ +LL + while false && true { + | "} -{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":821,"byte_end":824,"line_start":37,"line_end":37,"column_start":12,"column_end":15,"is_primary":true,"text":[{"text":" if (c) { +{"message":"unnecessary parentheses around `if` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":821,"byte_end":822,"line_start":37,"line_end":37,"column_start":12,"column_end":13,"is_primary":true,"text":[{"text":" if (c) { --> $DIR/unused_parens_remove_json_suggestion.rs:37:12 | LL | if (c) { - | ^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if (c) { +LL + if c { + | "} -{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":918,"byte_end":933,"line_start":43,"line_end":43,"column_start":10,"column_end":25,"is_primary":true,"text":[{"text":" while(true && false) { +{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":918,"byte_end":919,"line_start":43,"line_end":43,"column_start":10,"column_end":11,"is_primary":true,"text":[{"text":" while(true && false) { --> $DIR/unused_parens_remove_json_suggestion.rs:43:10 | LL | while(true && false) { - | ^^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while(true && false) { +LL + while true && false { + | "} -{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":987,"byte_end":995,"line_start":44,"line_end":44,"column_start":18,"column_end":26,"is_primary":true,"text":[{"text":" for _ in (0 .. 3){ +{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":987,"byte_end":988,"line_start":44,"line_end":44,"column_start":18,"column_end":19,"is_primary":true,"text":[{"text":" for _ in (0 .. 3){ --> $DIR/unused_parens_remove_json_suggestion.rs:44:18 | LL | for _ in (0 .. 3){ - | ^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - for _ in (0 .. 3){ +LL + for _ in 0 .. 3 { + | "} -{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1088,"byte_end":1096,"line_start":49,"line_end":49,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":" for _ in (0 .. 3) { +{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1088,"byte_end":1089,"line_start":49,"line_end":49,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" for _ in (0 .. 3) { --> $DIR/unused_parens_remove_json_suggestion.rs:49:14 | LL | for _ in (0 .. 3) { - | ^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - for _ in (0 .. 3) { +LL + for _ in 0 .. 3 { + | "} -{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1147,"byte_end":1162,"line_start":50,"line_end":50,"column_start":15,"column_end":30,"is_primary":true,"text":[{"text":" while (true && false) { +{"message":"unnecessary parentheses around `while` condition","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1147,"byte_end":1148,"line_start":50,"line_end":50,"column_start":15,"column_end":16,"is_primary":true,"text":[{"text":" while (true && false) { --> $DIR/unused_parens_remove_json_suggestion.rs:50:15 | LL | while (true && false) { - | ^^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - while (true && false) { +LL + while true && false { + | "} {"message":"aborting due to 9 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 9 previous errors diff --git a/src/test/ui/path-lookahead.stderr b/src/test/ui/path-lookahead.stderr index dcf235a9e2774..8adf02b150b87 100644 --- a/src/test/ui/path-lookahead.stderr +++ b/src/test/ui/path-lookahead.stderr @@ -2,13 +2,18 @@ warning: unnecessary parentheses around `return` value --> $DIR/path-lookahead.rs:10:12 | LL | return (::to_string(&arg)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/path-lookahead.rs:5:9 | LL | #![warn(unused_parens)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - return (::to_string(&arg)); +LL + return ::to_string(&arg); + | warning: 1 warning emitted diff --git a/src/test/ui/try-block/try-block-unused-delims.stderr b/src/test/ui/try-block/try-block-unused-delims.stderr index c5a2405462932..d8dd31645e061 100644 --- a/src/test/ui/try-block/try-block-unused-delims.stderr +++ b/src/test/ui/try-block/try-block-unused-delims.stderr @@ -2,43 +2,71 @@ warning: unnecessary parentheses around function argument --> $DIR/try-block-unused-delims.rs:11:13 | LL | consume((try {})); - | ^^^^^^^^ help: remove these parentheses + | ^ ^ | note: the lint level is defined here --> $DIR/try-block-unused-delims.rs:6:9 | LL | #![warn(unused_parens, unused_braces)] | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - consume((try {})); +LL + consume(try {}); + | warning: unnecessary braces around function argument --> $DIR/try-block-unused-delims.rs:14:13 | LL | consume({ try {} }); - | ^^^^^^^^^^ help: remove these braces + | ^^ ^^ | note: the lint level is defined here --> $DIR/try-block-unused-delims.rs:6:24 | LL | #![warn(unused_parens, unused_braces)] | ^^^^^^^^^^^^^ +help: remove these braces + | +LL - consume({ try {} }); +LL + consume(try {}); + | warning: unnecessary parentheses around `match` scrutinee expression --> $DIR/try-block-unused-delims.rs:17:11 | LL | match (try {}) { - | ^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - match (try {}) { +LL + match try {} { + | warning: unnecessary parentheses around `let` scrutinee expression --> $DIR/try-block-unused-delims.rs:22:22 | LL | if let Err(()) = (try {}) {} - | ^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - if let Err(()) = (try {}) {} +LL + if let Err(()) = try {} {} + | warning: unnecessary parentheses around `match` scrutinee expression --> $DIR/try-block-unused-delims.rs:25:11 | LL | match (try {}) { - | ^^^^^^^^ help: remove these parentheses + | ^ ^ + | +help: remove these parentheses + | +LL - match (try {}) { +LL + match try {} { + | warning: 5 warnings emitted