Fix Range warning and improve tests
This commit is contained in:
parent
46b07d670a
commit
47014df790
@ -376,8 +376,12 @@ impl EarlyLintPass for UnusedParens {
|
||||
}
|
||||
|
||||
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
|
||||
if let ast::PatKind::Paren(_) = p.node {
|
||||
self.check_unused_parens_pat(cx, &p, "pattern");
|
||||
use ast::PatKind::{Paren, Range};
|
||||
if let Paren(ref pat) = p.node {
|
||||
match pat.node {
|
||||
Range(..) => {}
|
||||
_ => self.check_unused_parens_pat(cx, &p, "pattern")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,29 +14,25 @@
|
||||
#![allow(unused_variables)]
|
||||
#![warn(unused_parens)]
|
||||
|
||||
struct A {
|
||||
field: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 3;
|
||||
match x {
|
||||
(_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
(y) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
(ref r) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
e @ 1...2 | (e @ (3...4)) => {}
|
||||
//~^ WARNING: unnecessary parentheses around pattern (3 ... 4)
|
||||
//~^ WARNING: unnecessary parentheses around pattern (e @ _)
|
||||
match 1 {
|
||||
(_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
(y) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
(ref r) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
(e @ 1..=2) => {} //~ WARNING: unnecessary parentheses around outer pattern
|
||||
(1..=2) => {} // Non ambiguous range pattern should not warn
|
||||
e @ (3..=4) => {} // Non ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
let field = "foo".to_string();
|
||||
let x: Option<A> = Some(A { field: Some(field) });
|
||||
match x {
|
||||
Some(A {
|
||||
field: (ref a @ Some(_)),
|
||||
//~^ WARNING: unnecessary parentheses around pattern
|
||||
..
|
||||
}) => {}
|
||||
_ => {}
|
||||
match &1 {
|
||||
(e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
|
||||
&(_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
e @ &(1...2) => {} // Ambiguous range pattern should not warn
|
||||
&(1..=2) => {} // Ambiguous range pattern should not warn
|
||||
}
|
||||
|
||||
match &1 {
|
||||
e @ &(1...2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
|
||||
&_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:24:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:19:9
|
||||
|
|
||||
LL | (_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
LL | (_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
||||
note: lint level defined here
|
||||
@ -11,32 +11,32 @@ LL | #![warn(unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:25:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:20:9
|
||||
|
|
||||
LL | (y) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
LL | (y) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:26:9
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:21:9
|
||||
|
|
||||
LL | (ref r) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
LL | (ref r) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:27:21
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:22:9
|
||||
|
|
||||
LL | e @ 1...2 | (e @ (3...4)) => {}
|
||||
| ^^^^^^^^^^^^^ help: remove these parentheses
|
||||
LL | (e @ 1..=2) => {} //~ WARNING: unnecessary parentheses around outer pattern
|
||||
| ^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:27:26
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:28:9
|
||||
|
|
||||
LL | e @ 1...2 | (e @ (3...4)) => {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
LL | (e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
|
||||
| ^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:36:20
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:29:10
|
||||
|
|
||||
LL | field: (ref a @ Some(_)),
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
LL | &(_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user