Skip to content

Commit 9d2eb9b

Browse files
committed
Rollup merge of rust-lang#55166 - varkor:ret-parens, r=davidtwco
Don't warn about parentheses on `match (return)` Fixes rust-lang#55164.
2 parents 8d712aa + 40bba70 commit 9d2eb9b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Diff for: src/librustc_lint/unused.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,13 @@ impl UnusedParens {
276276
cx: &EarlyContext,
277277
value: &ast::Expr,
278278
msg: &str,
279-
struct_lit_needs_parens: bool) {
279+
followed_by_block: bool) {
280280
if let ast::ExprKind::Paren(ref inner) = value.node {
281-
let necessary = struct_lit_needs_parens &&
282-
parser::contains_exterior_struct_lit(&inner);
281+
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
282+
true
283+
} else {
284+
parser::contains_exterior_struct_lit(&inner)
285+
};
283286
if !necessary {
284287
let pattern = pprust::expr_to_string(value);
285288
Self::remove_outer_parens(cx, value.span, &pattern, msg);
@@ -343,7 +346,7 @@ impl LintPass for UnusedParens {
343346
impl EarlyLintPass for UnusedParens {
344347
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
345348
use syntax::ast::ExprKind::*;
346-
let (value, msg, struct_lit_needs_parens) = match e.node {
349+
let (value, msg, followed_by_block) = match e.node {
347350
If(ref cond, ..) => (cond, "`if` condition", true),
348351
While(ref cond, ..) => (cond, "`while` condition", true),
349352
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
@@ -380,7 +383,7 @@ impl EarlyLintPass for UnusedParens {
380383
return;
381384
}
382385
};
383-
self.check_unused_parens_expr(cx, &value, msg, struct_lit_needs_parens);
386+
self.check_unused_parens_expr(cx, &value, msg, followed_by_block);
384387
}
385388

386389
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {

Diff for: src/test/ui/lint/no-unused-parens-return-block.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-pass
2+
3+
#![deny(unused_parens)]
4+
#![allow(unreachable_code)]
5+
6+
fn main() {
7+
match (return) {} // ok
8+
if (return) {} // ok
9+
}

0 commit comments

Comments
 (0)