From 64019e764f1837a4a19297fc9f7a99595e37cf51 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 25 Jun 2014 09:00:46 +1000 Subject: rustc: update the unnecessary parens lint for struct literals. Things like `match X { x: 1 } { ... }` now need to be written with parentheses, so the lint should avoid warning in cases like that. --- src/test/compile-fail/lint-unnecessary-parens.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/test') diff --git a/src/test/compile-fail/lint-unnecessary-parens.rs b/src/test/compile-fail/lint-unnecessary-parens.rs index b2abe025794..4d9383aeda2 100644 --- a/src/test/compile-fail/lint-unnecessary-parens.rs +++ b/src/test/compile-fail/lint-unnecessary-parens.rs @@ -10,18 +10,41 @@ #![deny(unnecessary_parens)] +#[deriving(Eq, PartialEq)] +struct X { y: bool } +impl X { + fn foo(&self) -> bool { self.y } +} + fn foo() -> int { return (1); //~ ERROR unnecessary parentheses around `return` value } +fn bar() -> X { + return (X { y: true }); //~ ERROR unnecessary parentheses around `return` value +} fn main() { foo(); + bar(); if (true) {} //~ ERROR unnecessary parentheses around `if` condition while (true) {} //~ ERROR unnecessary parentheses around `while` condition match (true) { //~ ERROR unnecessary parentheses around `match` head expression _ => {} } + let v = X { y: false }; + // struct lits needs parens, so these shouldn't warn. + if (v == X { y: true }) {} + if (X { y: true } == v) {} + if (X { y: false }.y) {} + + while (X { y: false }.foo()) {} + while (true | X { y: false }.y) {} + + match (X { y: false }) { + _ => {} + } + let mut _a = (0); //~ ERROR unnecessary parentheses around assigned value _a = (0); //~ ERROR unnecessary parentheses around assigned value _a += (1); //~ ERROR unnecessary parentheses around assigned value -- cgit 1.4.1-3-g733a5