未验证 提交 48915315 编写于 作者: M Matthias Krüger 提交者: GitHub

Rollup merge of #91956 - notriddle:notriddle/unused-parens-range, r=nagisa

fix(rustc_lint): better detect when parens are necessary

Fixes #90807
......@@ -478,8 +478,11 @@ fn is_expr_delims_necessary(
lhs_needs_parens
|| (followed_by_block
&& match inner.kind {
&& match &inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true,
ExprKind::Range(_lhs, Some(rhs), _limits) => {
matches!(rhs.kind, ExprKind::Block(..))
}
_ => parser::contains_exterior_struct_lit(&inner),
})
}
......
// Make sure unused parens lint emit is emitted for loop and match.
// See https://github.com/rust-lang/rust/issues/90807
// and https://github.com/rust-lang/rust/pull/91956#discussion_r771647953
#![deny(unused_parens)]
fn main() {
for _ in (1..loop { break 2 }) {} //~ERROR
for _ in (1..match () { () => 2 }) {} //~ERROR
}
error: unnecessary parentheses around `for` iterator expression
--> $DIR/issue-90807-unused-paren-error.rs:7:14
|
LL | for _ in (1..loop { break 2 }) {}
| ^ ^
|
note: the lint level is defined here
--> $DIR/issue-90807-unused-paren-error.rs:4:9
|
LL | #![deny(unused_parens)]
| ^^^^^^^^^^^^^
help: remove these parentheses
|
LL - for _ in (1..loop { break 2 }) {}
LL + for _ in 1..loop { break 2 } {}
|
error: unnecessary parentheses around `for` iterator expression
--> $DIR/issue-90807-unused-paren-error.rs:8:14
|
LL | for _ in (1..match () { () => 2 }) {}
| ^ ^
|
help: remove these parentheses
|
LL - for _ in (1..match () { () => 2 }) {}
LL + for _ in 1..match () { () => 2 } {}
|
error: aborting due to 2 previous errors
// check-pass
// Make sure unused parens lint doesn't emit a false positive.
// See https://github.com/rust-lang/rust/issues/90807
#![deny(unused_parens)]
fn main() {
for _ in (1..{ 2 }) {}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册