Skip to content

Commit 1a37575

Browse files
committed
don't lint unused_parens on if (break _)
1 parent 4e88b73 commit 1a37575

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/librustc_lint/unused.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,9 @@ impl UnusedParens {
278278
msg: &str,
279279
followed_by_block: bool) {
280280
if let ast::ExprKind::Paren(ref inner) = value.node {
281-
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
282-
true
283-
} else {
284-
parser::contains_exterior_struct_lit(&inner)
281+
let necessary = followed_by_block && match inner.node {
282+
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
283+
_ => parser::contains_exterior_struct_lit(&inner),
285284
};
286285
if !necessary {
287286
let expr_text = if let Ok(snippet) = cx.sess().source_map()

src/test/ui/lint/unused_parens_json_suggestion.rs

+9
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ fn main() {
2323
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
2424
// the malformed `1 / (2 + 3`
2525
let _a = (1 / (2 + 3));
26+
f();
27+
}
28+
29+
fn f() -> bool {
30+
loop {
31+
if (break { return true }) {
32+
}
33+
}
34+
false
2635
}

0 commit comments

Comments
 (0)