]> git.lizzy.rs Git - rust.git/blob - tests/ui/let_return.rs
Stabilize tool lints
[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
11
12
13 #![allow(unused)]
14
15 #![warn(clippy::let_and_return)]
16
17 fn test() -> i32 {
18     let _y = 0; // no warning
19     let x = 5;
20     x
21 }
22
23 fn test_inner() -> i32 {
24     if true {
25         let x = 5;
26         x
27     } else {
28         0
29     }
30 }
31
32 fn test_nowarn_1() -> i32 {
33     let mut x = 5;
34     x += 1;
35     x
36 }
37
38 fn test_nowarn_2() -> i32 {
39     let x = 5;
40     x + 1
41 }
42
43 fn test_nowarn_3() -> (i32, i32) {
44     // this should technically warn, but we do not compare complex patterns
45     let (x, y) = (5, 9);
46     (x, y)
47 }
48
49 fn test_nowarn_4() -> i32 {
50     // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type
51     let x: i32 = 5;
52     x
53 }
54
55 fn main() {
56 }