Skip to content

Commit

Permalink
Rollup merge of rust-lang#54885 - llogiq:fix-54704, r=nikomatsakis
Browse files Browse the repository at this point in the history
Don't lint 'unused_parens` on `if (break _) { .. }`

This fixes rust-lang#54704
  • Loading branch information
kennytm authored Oct 30, 2018
2 parents b1ca390 + 1a37575 commit df511e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,9 @@ impl UnusedParens {
msg: &str,
followed_by_block: bool) {
if let ast::ExprKind::Paren(ref inner) = value.node {
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
true
} else {
parser::contains_exterior_struct_lit(&inner)
let necessary = followed_by_block && match inner.node {
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
_ => parser::contains_exterior_struct_lit(&inner),
};
if !necessary {
let expr_text = if let Ok(snippet) = cx.sess().source_map()
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/lint/unused_parens_json_suggestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ fn main() {
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
// the malformed `1 / (2 + 3`
let _a = (1 / (2 + 3));
f();
}

fn f() -> bool {
loop {
if (break { return true }) {
}
}
false
}

0 comments on commit df511e9

Please sign in to comment.