Simply unused_parens check and add tests
This commit is contained in:
parent
5217527a5b
commit
46b07d670a
4 changed files with 95 additions and 18 deletions
42
src/test/ui/lint/issue-54538-unused-parens-lint.rs
Normal file
42
src/test/ui/lint/issue-54538-unused-parens-lint.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
#![allow(unreachable_patterns)]
|
||||
#![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 @ _)
|
||||
}
|
||||
|
||||
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
|
||||
..
|
||||
}) => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
42
src/test/ui/lint/issue-54538-unused-parens-lint.stderr
Normal file
42
src/test/ui/lint/issue-54538-unused-parens-lint.stderr
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:24:9
|
||||
|
|
||||
LL | (_) => {} //~ WARNING: unnecessary parentheses around pattern
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:15:9
|
||||
|
|
||||
LL | #![warn(unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:25:9
|
||||
|
|
||||
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
|
||||
|
|
||||
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
|
||||
|
|
||||
LL | e @ 1...2 | (e @ (3...4)) => {}
|
||||
| ^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:27:26
|
||||
|
|
||||
LL | e @ 1...2 | (e @ (3...4)) => {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
warning: unnecessary parentheses around pattern
|
||||
--> $DIR/issue-54538-unused-parens-lint.rs:36:20
|
||||
|
|
||||
LL | field: (ref a @ Some(_)),
|
||||
| ^^^^^^^^^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue