]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/let_if_seq.rs
Add a `USELESS_LET_IF_SEQ` lint
[rust.git] / tests / compile-fail / let_if_seq.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![allow(unused_variables, unused_assignments, similar_names, blacklisted_name)]
5 #![deny(useless_let_if_seq)]
6
7 fn f() -> bool { true }
8
9 fn early_return() -> u8 {
10     // FIXME: we could extend the lint to include such cases:
11     let foo;
12
13     if f() {
14         return 42;
15     } else {
16         foo = 0;
17     }
18
19     foo
20 }
21
22 fn main() {
23     early_return();
24
25     let mut foo = 0;
26     //~^ ERROR `if _ { .. } else { .. }` is an expression
27     //~| HELP more idiomatic
28     //~| SUGGESTION let <mut> foo = if f() { 42 } else { 0 };
29     if f() {
30         foo = 42;
31     }
32
33     let mut bar = 0;
34     //~^ ERROR `if _ { .. } else { .. }` is an expression
35     //~| HELP more idiomatic
36     //~| SUGGESTION let <mut> bar = if f() { ..; 42 } else { ..; 0 };
37     if f() {
38         f();
39         bar = 42;
40     }
41     else {
42         f();
43     }
44
45     let quz;
46     //~^ ERROR `if _ { .. } else { .. }` is an expression
47     //~| HELP more idiomatic
48     //~| SUGGESTION let quz = if f() { 42 } else { 0 };
49
50     if f() {
51         quz = 42;
52     } else {
53         quz = 0;
54     }
55
56     // `toto` is used several times
57     let mut toto;
58
59     if f() {
60         toto = 42;
61     } else {
62         for i in &[1, 2] {
63             toto = *i;
64         }
65
66         toto = 2;
67     }
68
69     // baz needs to be mut
70     let mut baz = 0;
71     //~^ ERROR `if _ { .. } else { .. }` is an expression
72     //~| HELP more idiomatic
73     //~| SUGGESTION let <mut> baz = if f() { 42 } else { 0 };
74     if f() {
75         baz = 42;
76     }
77
78     baz = 1337;
79 }