diff options
| author | Andre Bogus <bogusandre@gmail.com> | 2018-10-29 12:41:50 +0100 |
|---|---|---|
| committer | Andre Bogus <bogusandre@gmail.com> | 2018-10-29 12:41:56 +0100 |
| commit | 1a37575ade6dafedca29ffa03edbf2167cc1e544 (patch) | |
| tree | ac628d33558b20bc8fc68b05d8c2c7ed59eed8e6 | |
| parent | 4e88b7363b7858960ccfd87326ece9d00bf4d973 (diff) | |
| download | rust-1a37575ade6dafedca29ffa03edbf2167cc1e544.tar.gz rust-1a37575ade6dafedca29ffa03edbf2167cc1e544.zip | |
don't lint `unused_parens` on `if (break _)`
| -rw-r--r-- | src/librustc_lint/unused.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/lint/unused_parens_json_suggestion.rs | 9 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 96d04253cc4..5950e19b0ee 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -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() diff --git a/src/test/ui/lint/unused_parens_json_suggestion.rs b/src/test/ui/lint/unused_parens_json_suggestion.rs index 187e7f31dfd..9eda59614f4 100644 --- a/src/test/ui/lint/unused_parens_json_suggestion.rs +++ b/src/test/ui/lint/unused_parens_json_suggestion.rs @@ -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 } |
