Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn about parentheses on match (return) #55166

Merged
merged 2 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ impl UnusedParens {
cx: &EarlyContext,
value: &ast::Expr,
msg: &str,
struct_lit_needs_parens: bool) {
followed_by_block: bool) {
if let ast::ExprKind::Paren(ref inner) = value.node {
let necessary = struct_lit_needs_parens &&
parser::contains_exterior_struct_lit(&inner);
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
true
} else {
parser::contains_exterior_struct_lit(&inner)
};
if !necessary {
let pattern = pprust::expr_to_string(value);
Self::remove_outer_parens(cx, value.span, &pattern, msg);
Expand Down Expand Up @@ -343,7 +346,7 @@ impl LintPass for UnusedParens {
impl EarlyLintPass for UnusedParens {
fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
use syntax::ast::ExprKind::*;
let (value, msg, struct_lit_needs_parens) = match e.node {
let (value, msg, followed_by_block) = match e.node {
If(ref cond, ..) => (cond, "`if` condition", true),
While(ref cond, ..) => (cond, "`while` condition", true),
IfLet(_, ref cond, ..) => (cond, "`if let` head expression", true),
Expand Down Expand Up @@ -380,7 +383,7 @@ impl EarlyLintPass for UnusedParens {
return;
}
};
self.check_unused_parens_expr(cx, &value, msg, struct_lit_needs_parens);
self.check_unused_parens_expr(cx, &value, msg, followed_by_block);
}

fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/lint/no-unused-parens-return-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-pass

fn main() {
match (return) {} // ok
if (return) {} // ok
}