]> git.lizzy.rs Git - rust.git/blob - tests/ui/let_if_seq.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / let_if_seq.rs
1 #![feature(tool_lints)]
2
3
4 #![allow(unused_variables, unused_assignments, clippy::similar_names, clippy::blacklisted_name)]
5 #![warn(clippy::useless_let_if_seq)]
6
7 fn f() -> bool { true }
8 fn g(x: i32) -> i32 { x + 1 }
9
10 fn issue985() -> i32 {
11     let mut x = 42;
12     if f() {
13         x = g(x);
14     }
15
16     x
17 }
18
19 fn issue985_alt() -> i32 {
20     let mut x = 42;
21     if f() {
22         f();
23     } else {
24         x = g(x);
25     }
26
27     x
28 }
29
30 fn issue975() -> String {
31     let mut udn = "dummy".to_string();
32     if udn.starts_with("uuid:") {
33         udn = String::from(&udn[5..]);
34     }
35     udn
36 }
37
38 fn early_return() -> u8 {
39     // FIXME: we could extend the lint to include such cases:
40     let foo;
41
42     if f() {
43         return 42;
44     } else {
45         foo = 0;
46     }
47
48     foo
49 }
50
51 fn main() {
52     early_return();
53     issue975();
54     issue985();
55     issue985_alt();
56
57     let mut foo = 0;
58     if f() {
59         foo = 42;
60     }
61
62     let mut bar = 0;
63     if f() {
64         f();
65         bar = 42;
66     }
67     else {
68         f();
69     }
70
71     let quz;
72     if f() {
73         quz = 42;
74     } else {
75         quz = 0;
76     }
77
78     // `toto` is used several times
79     let mut toto;
80     if f() {
81         toto = 42;
82     } else {
83         for i in &[1, 2] {
84             toto = *i;
85         }
86
87         toto = 2;
88     }
89
90     // found in libcore, the inner if is not a statement but the block's expr
91     let mut ch = b'x';
92     if f() {
93         ch = b'*';
94         if f() {
95             ch = b'?';
96         }
97     }
98
99     // baz needs to be mut
100     let mut baz = 0;
101     if f() {
102         baz = 42;
103     }
104
105     baz = 1337;
106 }