]> git.lizzy.rs Git - rust.git/blob - tests/ui/let_return.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / let_return.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(unused)]
11 #![warn(clippy::let_and_return)]
12
13 fn test() -> i32 {
14     let _y = 0; // no warning
15     let x = 5;
16     x
17 }
18
19 fn test_inner() -> i32 {
20     if true {
21         let x = 5;
22         x
23     } else {
24         0
25     }
26 }
27
28 fn test_nowarn_1() -> i32 {
29     let mut x = 5;
30     x += 1;
31     x
32 }
33
34 fn test_nowarn_2() -> i32 {
35     let x = 5;
36     x + 1
37 }
38
39 fn test_nowarn_3() -> (i32, i32) {
40     // this should technically warn, but we do not compare complex patterns
41     let (x, y) = (5, 9);
42     (x, y)
43 }
44
45 fn test_nowarn_4() -> i32 {
46     // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type
47     let x: i32 = 5;
48     x
49 }
50
51 fn main() {}