]> git.lizzy.rs Git - rust.git/blob - tests/ui/let_return.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / let_return.rs
1 #![allow(unused)]
2 #![warn(clippy::let_and_return)]
3
4 fn test() -> i32 {
5     let _y = 0; // no warning
6     let x = 5;
7     x
8 }
9
10 fn test_inner() -> i32 {
11     if true {
12         let x = 5;
13         x
14     } else {
15         0
16     }
17 }
18
19 fn test_nowarn_1() -> i32 {
20     let mut x = 5;
21     x += 1;
22     x
23 }
24
25 fn test_nowarn_2() -> i32 {
26     let x = 5;
27     x + 1
28 }
29
30 fn test_nowarn_3() -> (i32, i32) {
31     // this should technically warn, but we do not compare complex patterns
32     let (x, y) = (5, 9);
33     (x, y)
34 }
35
36 fn test_nowarn_4() -> i32 {
37     // this should technically warn, but not b/c of clippy::let_and_return, but b/c of useless type
38     let x: i32 = 5;
39     x
40 }
41
42 fn test_nowarn_5(x: i16) -> u16 {
43     #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
44     let x = x as u16;
45     x
46 }
47
48 fn main() {}