forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#123314 - surechen:fix_120642, r=Nadrieril
Skip `unused_parens` report for `Paren(Path(..))` in macro. fixes rust-lang#120642 In following code, `unused_parens` suggest change `<($($rest),*)>::bar()` to `<$rest>::bar()` which will cause another err: `error: variable 'rest' is still repeating at this depth`: ```rust trait Foo { fn bar(); } macro_rules! problem { ($ty:ident) => { impl<$ty: Foo> Foo for ($ty,) { fn bar() { <$ty>::bar() } } }; ($ty:ident $(, $rest:ident)*) => { impl<$ty: Foo, $($rest: Foo),*> Foo for ($ty, $($rest),*) { fn bar() { <$ty>::bar(); <($($rest),*)>::bar() } } problem!($($rest),*); } } ``` I think maybe we can handle this by avoid warning for `Paren(Path(..))` in the macro. Is this reasonable approach?
- Loading branch information
Showing
3 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/ui/lint/unused/unused_parens/unused-parens-in-macro-issue-120642.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//@ run-pass | ||
|
||
#![warn(unused_parens)] | ||
#![allow(dead_code)] | ||
|
||
trait Foo { | ||
fn bar(); | ||
fn tar(); | ||
} | ||
|
||
macro_rules! unused_parens { | ||
($ty:ident) => { | ||
impl<$ty: Foo> Foo for ($ty,) { | ||
fn bar() { <$ty>::bar() } | ||
fn tar() {} | ||
} | ||
}; | ||
|
||
($ty:ident $(, $rest:ident)*) => { | ||
impl<$ty: Foo, $($rest: Foo),*> Foo for ($ty, $($rest),*) { | ||
fn bar() { | ||
<$ty>::bar(); | ||
<($($rest),*)>::bar() //~WARN unnecessary parentheses around type | ||
} | ||
fn tar() { | ||
let (_t) = 1; //~WARN unnecessary parentheses around pattern | ||
//~| WARN unnecessary parentheses around pattern | ||
let (_t1,) = (1,); | ||
let (_t2, _t3) = (1, 2); | ||
} | ||
} | ||
|
||
unused_parens!($($rest),*); | ||
} | ||
} | ||
|
||
unused_parens!(T1, T2, T3); | ||
|
||
fn main() {} |
40 changes: 40 additions & 0 deletions
40
tests/ui/lint/unused/unused_parens/unused-parens-in-macro-issue-120642.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
warning: unnecessary parentheses around pattern | ||
--> $DIR/unused-parens-in-macro-issue-120642.rs:26:19 | ||
| | ||
LL | let (_t) = 1; | ||
| ^^^^ | ||
... | ||
LL | unused_parens!(T1, T2, T3); | ||
| -------------------------- in this macro invocation | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-parens-in-macro-issue-120642.rs:3:9 | ||
| | ||
LL | #![warn(unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
= note: this warning originates in the macro `unused_parens` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: unnecessary parentheses around type | ||
--> $DIR/unused-parens-in-macro-issue-120642.rs:23:18 | ||
| | ||
LL | <($($rest),*)>::bar() | ||
| ^^^^^^^^^^^^ | ||
... | ||
LL | unused_parens!(T1, T2, T3); | ||
| -------------------------- in this macro invocation | ||
| | ||
= note: this warning originates in the macro `unused_parens` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: unnecessary parentheses around pattern | ||
--> $DIR/unused-parens-in-macro-issue-120642.rs:26:19 | ||
| | ||
LL | let (_t) = 1; | ||
| ^^^^ | ||
... | ||
LL | unused_parens!(T1, T2, T3); | ||
| -------------------------- in this macro invocation | ||
| | ||
= note: this warning originates in the macro `unused_parens` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
warning: 3 warnings emitted | ||
|