forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#132936 - surechen:fix_131989, r=Nadrieril
For expr `return (_ = 42);` unused_paren lint should not be triggered fixes rust-lang#131989
- Loading branch information
Showing
13 changed files
with
189 additions
and
40 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
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
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
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
32 changes: 32 additions & 0 deletions
32
tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.fixed
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,32 @@ | ||
//@ run-rustfix | ||
#![deny(unused_parens)] | ||
#![allow(unreachable_code)] | ||
|
||
fn foo() { | ||
loop { | ||
break (_ = 42); | ||
// lint unused_parens should not be triggered here. | ||
} | ||
|
||
let _ = loop { | ||
let a = 1; | ||
let b = 2; | ||
break a + b; //~ERROR unnecessary parentheses | ||
}; | ||
|
||
loop { | ||
if break return () { | ||
//~^ ERROR unnecessary parentheses | ||
} | ||
if break return () { | ||
//~^ ERROR unnecessary parentheses | ||
} | ||
} | ||
|
||
return (_ = 42); | ||
// lint unused_parens should not be triggered here. | ||
} | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.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,32 @@ | ||
//@ run-rustfix | ||
#![deny(unused_parens)] | ||
#![allow(unreachable_code)] | ||
|
||
fn foo() { | ||
loop { | ||
break (_ = 42); | ||
// lint unused_parens should not be triggered here. | ||
} | ||
|
||
let _ = loop { | ||
let a = 1; | ||
let b = 2; | ||
break (a + b); //~ERROR unnecessary parentheses | ||
}; | ||
|
||
loop { | ||
if (break return ()) { | ||
//~^ ERROR unnecessary parentheses | ||
} | ||
if break (return ()) { | ||
//~^ ERROR unnecessary parentheses | ||
} | ||
} | ||
|
||
return (_ = 42); | ||
// lint unused_parens should not be triggered here. | ||
} | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/ui/lint/unused/unused-parens-assign-expr-in-ret-issue-131989.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,43 @@ | ||
error: unnecessary parentheses around `break` value | ||
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:14:15 | ||
| | ||
LL | break (a + b); | ||
| ^ ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:2:9 | ||
| | ||
LL | #![deny(unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
help: remove these parentheses | ||
| | ||
LL - break (a + b); | ||
LL + break a + b; | ||
| | ||
|
||
error: unnecessary parentheses around `if` condition | ||
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:18:12 | ||
| | ||
LL | if (break return ()) { | ||
| ^ ^ | ||
| | ||
help: remove these parentheses | ||
| | ||
LL - if (break return ()) { | ||
LL + if break return () { | ||
| | ||
|
||
error: unnecessary parentheses around `break` value | ||
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:21:18 | ||
| | ||
LL | if break (return ()) { | ||
| ^ ^ | ||
| | ||
help: remove these parentheses | ||
| | ||
LL - if break (return ()) { | ||
LL + if break return () { | ||
| | ||
|
||
error: aborting due to 3 previous errors | ||
|
Oops, something went wrong.