]> git.lizzy.rs Git - rust.git/blob - tests/ui/branches_sharing_code/shared_at_top_and_bottom.rs
Rollup merge of #92849 - flip1995:clippyup, r=Manishearth
[rust.git] / tests / ui / branches_sharing_code / shared_at_top_and_bottom.rs
1 #![allow(dead_code)]
2 #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
3
4 // branches_sharing_code at the top and bottom of the if blocks
5
6 struct DataPack {
7     id: u32,
8     name: String,
9     some_data: Vec<u8>,
10 }
11
12 fn overlapping_eq_regions() {
13     let x = 9;
14
15     // Overlap with separator
16     if x == 7 {
17         let t = 7;
18         let _overlap_start = t * 2;
19         let _overlap_end = 2 * t;
20         let _u = 9;
21     } else {
22         let t = 7;
23         let _overlap_start = t * 2;
24         let _overlap_end = 2 * t;
25         println!("Overlap separator");
26         let _overlap_start = t * 2;
27         let _overlap_end = 2 * t;
28         let _u = 9;
29     }
30
31     // Overlap with separator
32     if x == 99 {
33         let r = 7;
34         let _overlap_start = r;
35         let _overlap_middle = r * r;
36         let _overlap_end = r * r * r;
37         let z = "end";
38     } else {
39         let r = 7;
40         let _overlap_start = r;
41         let _overlap_middle = r * r;
42         let _overlap_middle = r * r;
43         let _overlap_end = r * r * r;
44         let z = "end";
45     }
46 }
47
48 fn complexer_example() {
49     fn gen_id(x: u32, y: u32) -> u32 {
50         let x = x & 0x0000_ffff;
51         let y = (y & 0xffff_0000) << 16;
52         x | y
53     }
54
55     fn process_data(data: DataPack) {
56         let _ = data;
57     }
58
59     let x = 8;
60     let y = 9;
61     if (x > 7 && y < 13) || (x + y) % 2 == 1 {
62         let a = 0xcafe;
63         let b = 0xffff00ff;
64         let e_id = gen_id(a, b);
65
66         println!("From the a `{}` to the b `{}`", a, b);
67
68         let pack = DataPack {
69             id: e_id,
70             name: "Player 1".to_string(),
71             some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90],
72         };
73         process_data(pack);
74     } else {
75         let a = 0xcafe;
76         let b = 0xffff00ff;
77         let e_id = gen_id(a, b);
78
79         println!("The new ID is '{}'", e_id);
80
81         let pack = DataPack {
82             id: e_id,
83             name: "Player 1".to_string(),
84             some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90],
85         };
86         process_data(pack);
87     }
88 }
89
90 /// This should add a note to the lint msg since the moved expression is not `()`
91 fn added_note_for_expression_use() -> u32 {
92     let x = 9;
93
94     let _ = if x == 7 {
95         let _ = 19;
96
97         let _splitter = 6;
98
99         x << 2
100     } else {
101         let _ = 19;
102
103         x << 2
104     };
105
106     if x == 9 {
107         let _ = 17;
108
109         let _splitter = 6;
110
111         x * 4
112     } else {
113         let _ = 17;
114
115         x * 4
116     }
117 }
118
119 fn main() {}