about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-27 17:56:26 +0000
committerbors <bors@rust-lang.org>2014-06-27 17:56:26 +0000
commitabdf71cf73fd8b0b5bca78da830fe6f2a49ff8c2 (patch)
treee2441ed043a2a7eb038e62efde9cedf505c26d25 /src/test
parentd0983872efeea757600031a081a2eff9676fe895 (diff)
parent64019e764f1837a4a19297fc9f7a99595e37cf51 (diff)
downloadrust-abdf71cf73fd8b0b5bca78da830fe6f2a49ff8c2.tar.gz
rust-abdf71cf73fd8b0b5bca78da830fe6f2a49ff8c2.zip
auto merge of #15212 : huonw/rust/struct-paren-lint, r=alexcrichton
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.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/lint-unnecessary-parens.rs23
1 files changed, 23 insertions, 0 deletions
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