Skip to content

Commit

Permalink
Fix #66295
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed Dec 3, 2019
1 parent 4787e97 commit 3aa9902
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use syntax::print::pprust;
use syntax::symbol::{kw, sym};
use syntax::symbol::Symbol;
use syntax::util::parser;
use syntax_pos::{Span, BytePos};
use syntax_pos::{MultiSpan, Span, BytePos};

use log::debug;

Expand Down Expand Up @@ -355,7 +355,11 @@ impl UnusedParens {
match value.kind {
ast::ExprKind::Paren(ref inner) => {
if !Self::is_expr_parens_necessary(inner, followed_by_block) &&
value.attrs.is_empty() {
value.attrs.is_empty() &&
!MultiSpan::from(value.span).primary_span()
.map(|span| span.from_expansion())
.unwrap_or(false)
{
let expr_text = if let Ok(snippet) = cx.sess().source_map()
.span_to_snippet(value.span) {
snippet
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/lint/lint-unnecessary-parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ fn passes_unused_parens_lint() -> &'static (dyn Trait) {
panic!()
}

macro_rules! baz {
($($foo:expr),+) => {
($($foo),*)
}
}

fn main() {
foo();
bar((true)); //~ ERROR unnecessary parentheses around function argument
Expand Down Expand Up @@ -55,4 +61,7 @@ fn main() {
let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value
_a = (0); //~ ERROR unnecessary parentheses around assigned value
_a += (1); //~ ERROR unnecessary parentheses around assigned value

let _a = baz!(3, 4);
let _b = baz!(3);
}
22 changes: 11 additions & 11 deletions src/test/ui/lint/lint-unnecessary-parens.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,69 +23,69 @@ LL | fn unused_parens_around_return_type() -> (u32) {
| ^^^^^ help: remove these parentheses

error: unnecessary parentheses around function argument
--> $DIR/lint-unnecessary-parens.rs:30:9
--> $DIR/lint-unnecessary-parens.rs:36:9
|
LL | bar((true));
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `if` condition
--> $DIR/lint-unnecessary-parens.rs:32:8
--> $DIR/lint-unnecessary-parens.rs:38:8
|
LL | if (true) {}
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `while` condition
--> $DIR/lint-unnecessary-parens.rs:33:11
--> $DIR/lint-unnecessary-parens.rs:39:11
|
LL | while (true) {}
| ^^^^^^ help: remove these parentheses

warning: denote infinite loops with `loop { ... }`
--> $DIR/lint-unnecessary-parens.rs:33:5
--> $DIR/lint-unnecessary-parens.rs:39:5
|
LL | while (true) {}
| ^^^^^^^^^^^^ help: use `loop`
|
= note: `#[warn(while_true)]` on by default

error: unnecessary parentheses around `match` head expression
--> $DIR/lint-unnecessary-parens.rs:35:11
--> $DIR/lint-unnecessary-parens.rs:41:11
|
LL | match (true) {
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `let` head expression
--> $DIR/lint-unnecessary-parens.rs:38:16
--> $DIR/lint-unnecessary-parens.rs:44:16
|
LL | if let 1 = (1) {}
| ^^^ help: remove these parentheses

error: unnecessary parentheses around `let` head expression
--> $DIR/lint-unnecessary-parens.rs:39:19
--> $DIR/lint-unnecessary-parens.rs:45:19
|
LL | while let 1 = (2) {}
| ^^^ help: remove these parentheses

error: unnecessary parentheses around method argument
--> $DIR/lint-unnecessary-parens.rs:53:24
--> $DIR/lint-unnecessary-parens.rs:59:24
|
LL | X { y: false }.foo((true));
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:55:18
--> $DIR/lint-unnecessary-parens.rs:61:18
|
LL | let mut _a = (0);
| ^^^ help: remove these parentheses

error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:56:10
--> $DIR/lint-unnecessary-parens.rs:62:10
|
LL | _a = (0);
| ^^^ help: remove these parentheses

error: unnecessary parentheses around assigned value
--> $DIR/lint-unnecessary-parens.rs:57:11
--> $DIR/lint-unnecessary-parens.rs:63:11
|
LL | _a += (1);
| ^^^ help: remove these parentheses
Expand Down

0 comments on commit 3aa9902

Please sign in to comment.