Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused_parens triggers on macro by example code #66983

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ 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() &&
!value.span.from_expansion()
{
let expr_text = if let Ok(snippet) = cx.sess().source_map()
.span_to_snippet(value.span) {
snippet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ macro_rules! the_worship_the_heart_lifts_above {

macro_rules! and_the_heavens_reject_not {
() => {
// ↓ But let's test that we still lint for unused parens around
// function args inside of simple, one-deep macros.
#[allow(dead_code)] fn the_night_for_the_morrow() -> Option<isize> { Some((2)) }
//~^ WARN unnecessary parentheses around function argument
}
}

Expand Down

This file was deleted.

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