forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#131546 - surechen:fix_129833, r=jieyouxu Make unused_parens's suggestion considering expr's attributes. For the expr with attributes, like `let _ = (#[inline] || println!("Hello!"));`, the suggestion's span should contains the attributes, or the suggestion will remove them. fixes rust-lang#129833
- Loading branch information
Showing
4 changed files
with
70 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.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,15 @@ | ||
//@ run-rustfix | ||
// Check the `unused_parens` suggestion for paren_expr with attributes. | ||
// The suggestion should retain attributes in the front. | ||
|
||
#![feature(stmt_expr_attributes)] | ||
#![deny(unused_parens)] | ||
|
||
pub fn foo() -> impl Fn() { | ||
let _ = #[inline] #[allow(dead_code)] || println!("Hello!"); //~ERROR unnecessary parentheses | ||
#[inline] #[allow(dead_code)] || println!("Hello!") //~ERROR unnecessary parentheses | ||
} | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.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,15 @@ | ||
//@ run-rustfix | ||
// Check the `unused_parens` suggestion for paren_expr with attributes. | ||
// The suggestion should retain attributes in the front. | ||
|
||
#![feature(stmt_expr_attributes)] | ||
#![deny(unused_parens)] | ||
|
||
pub fn foo() -> impl Fn() { | ||
let _ = (#[inline] #[allow(dead_code)] || println!("Hello!")); //~ERROR unnecessary parentheses | ||
(#[inline] #[allow(dead_code)] || println!("Hello!")) //~ERROR unnecessary parentheses | ||
} | ||
|
||
fn main() { | ||
let _ = foo(); | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/ui/lint/unused/unused-parens-for-stmt-expr-attributes-issue-129833.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,31 @@ | ||
error: unnecessary parentheses around assigned value | ||
--> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:9:13 | ||
| | ||
LL | let _ = (#[inline] #[allow(dead_code)] || println!("Hello!")); | ||
| ^ ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:6:9 | ||
| | ||
LL | #![deny(unused_parens)] | ||
| ^^^^^^^^^^^^^ | ||
help: remove these parentheses | ||
| | ||
LL - let _ = (#[inline] #[allow(dead_code)] || println!("Hello!")); | ||
LL + let _ = #[inline] #[allow(dead_code)] || println!("Hello!"); | ||
| | ||
|
||
error: unnecessary parentheses around block return value | ||
--> $DIR/unused-parens-for-stmt-expr-attributes-issue-129833.rs:10:5 | ||
| | ||
LL | (#[inline] #[allow(dead_code)] || println!("Hello!")) | ||
| ^ ^ | ||
| | ||
help: remove these parentheses | ||
| | ||
LL - (#[inline] #[allow(dead_code)] || println!("Hello!")) | ||
LL + #[inline] #[allow(dead_code)] || println!("Hello!") | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|