]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lint-unnecessary-parens.rs
Removed some unnecessary RefCells from resolve
[rust.git] / src / test / compile-fail / lint-unnecessary-parens.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![deny(unnecessary_parens)]
12
13 #[deriving(Eq, PartialEq)]
14 struct X { y: bool }
15 impl X {
16     fn foo(&self) -> bool { self.y }
17 }
18
19 fn foo() -> int {
20     return (1i); //~ ERROR unnecessary parentheses around `return` value
21 }
22 fn bar() -> X {
23     return (X { y: true }); //~ ERROR unnecessary parentheses around `return` value
24 }
25
26 fn main() {
27     foo();
28     bar();
29
30     if (true) {} //~ ERROR unnecessary parentheses around `if` condition
31     while (true) {} //~ ERROR unnecessary parentheses around `while` condition
32     match (true) { //~ ERROR unnecessary parentheses around `match` head expression
33         _ => {}
34     }
35     let v = X { y: false };
36     // struct lits needs parens, so these shouldn't warn.
37     if (v == X { y: true }) {}
38     if (X { y: true } == v) {}
39     if (X { y: false }.y) {}
40
41     while (X { y: false }.foo()) {}
42     while (true | X { y: false }.y) {}
43
44     match (X { y: false }) {
45         _ => {}
46     }
47
48     let mut _a = (0i); //~ ERROR unnecessary parentheses around assigned value
49     _a = (0i); //~ ERROR unnecessary parentheses around assigned value
50     _a += (1i); //~ ERROR unnecessary parentheses around assigned value
51 }