Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 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,9 @@
// run-pass

#![deny(unused_parens)]
#![allow(unreachable_code)]

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