remove false positives of unused_braces
This commit is contained in:
parent
39b62533c7
commit
817f05986a
5 changed files with 72 additions and 25 deletions
|
|
@ -1,29 +1,48 @@
|
|||
// check-pass
|
||||
#![warn(unused_braces, unused_parens)]
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
let _ = (7);
|
||||
//~^WARN unnecessary parentheses
|
||||
|
||||
let _ = { 7 };
|
||||
//~^ WARN unnecessary braces
|
||||
// Do not emit a lint in these cases,
|
||||
// as we have to be careful with
|
||||
// `ref` patterns.
|
||||
{
|
||||
let _ = { 7 };
|
||||
|
||||
if let 7 = { 7 } {
|
||||
if let 7 = { 7 } { }
|
||||
|
||||
match { 7 } {
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
if { true } {
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
||||
|
||||
while { false } {
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
||||
|
||||
let _: [u8; { 3 }];
|
||||
//~^ WARN unnecessary braces
|
||||
|
||||
// do not emit error for multiline blocks.
|
||||
consume({ 7 });
|
||||
//~^ WARN unnecessary braces
|
||||
|
||||
// Do not emit lint for multiline blocks.
|
||||
let _ = {
|
||||
7
|
||||
};
|
||||
|
||||
// do not emit error for unsafe blocks.
|
||||
// Do not emit lint for unsafe blocks.
|
||||
let _ = unsafe { 7 };
|
||||
|
||||
// do not emit error, as the `{` would then
|
||||
// Do not emit lint, as the `{` would then
|
||||
// be parsed as part of the `return`.
|
||||
if { return } {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: unnecessary parentheses around assigned value
|
||||
--> $DIR/unused_braces.rs:5:13
|
||||
--> $DIR/unused_braces.rs:7:13
|
||||
|
|
||||
LL | let _ = (7);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
|
@ -10,11 +10,11 @@ note: the lint level is defined here
|
|||
LL | #![warn(unused_braces, unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary braces around assigned value
|
||||
--> $DIR/unused_braces.rs:8:13
|
||||
warning: unnecessary braces around `if` condition
|
||||
--> $DIR/unused_braces.rs:23:8
|
||||
|
|
||||
LL | let _ = { 7 };
|
||||
| ^^^^^ help: remove these braces
|
||||
LL | if { true } {
|
||||
| ^^^^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_braces.rs:2:9
|
||||
|
|
@ -22,15 +22,21 @@ note: the lint level is defined here
|
|||
LL | #![warn(unused_braces, unused_parens)]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: unnecessary braces around `let` scrutinee expression
|
||||
--> $DIR/unused_braces.rs:11:16
|
||||
warning: unnecessary braces around `while` condition
|
||||
--> $DIR/unused_braces.rs:27:11
|
||||
|
|
||||
LL | if let 7 = { 7 } {
|
||||
| ^^^^^ help: remove these braces
|
||||
LL | while { false } {
|
||||
| ^^^^^^^^^ help: remove these braces
|
||||
|
||||
warning: unnecessary braces around const expression
|
||||
--> $DIR/unused_braces.rs:15:17
|
||||
--> $DIR/unused_braces.rs:31:17
|
||||
|
|
||||
LL | let _: [u8; { 3 }];
|
||||
| ^^^^^ help: remove these braces
|
||||
|
||||
warning: unnecessary braces around function argument
|
||||
--> $DIR/unused_braces.rs:34:13
|
||||
|
|
||||
LL | consume({ 7 });
|
||||
| ^^^^^ help: remove these braces
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,15 @@ struct A {
|
|||
b: u32,
|
||||
}
|
||||
|
||||
fn consume<T>(_: T) {}
|
||||
|
||||
fn main() {
|
||||
let a = A {
|
||||
a: 42,
|
||||
b: 1729,
|
||||
};
|
||||
|
||||
let _ = &{ a.b };
|
||||
let _ = { a.b };
|
||||
consume(&{ a.b });
|
||||
consume({ a.b });
|
||||
//~^ WARN unnecessary braces
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
warning: unnecessary braces around assigned value
|
||||
--> $DIR/unused_parens_borrow.rs:20:13
|
||||
warning: unnecessary braces around function argument
|
||||
--> $DIR/unused_braces_borrow.rs:22:13
|
||||
|
|
||||
LL | let _ = { a.b };
|
||||
LL | consume({ a.b });
|
||||
| ^^^^^^^ help: remove these braces
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/unused_parens_borrow.rs:2:9
|
||||
--> $DIR/unused_braces_borrow.rs:2:9
|
||||
|
|
||||
LL | #![warn(unused_braces)]
|
||||
| ^^^^^^^^^^^^^
|
||||
Loading…
Add table
Add a link
Reference in a new issue