]> git.lizzy.rs Git - rust.git/blob - tests/ui/let_unit.rs
Merge branch 'master' into add-lints-aseert-checks
[rust.git] / tests / ui / let_unit.rs
1 #![warn(clippy::let_unit_value)]
2 #![allow(unused_variables)]
3
4 macro_rules! let_and_return {
5     ($n:expr) => {{
6         let ret = $n;
7     }};
8 }
9
10 fn main() {
11     let _x = println!("x");
12     let _y = 1; // this is fine
13     let _z = ((), 1); // this as well
14     if true {
15         let _a = ();
16     }
17
18     consume_units_with_for_loop(); // should be fine as well
19
20     let_and_return!(()) // should be fine
21 }
22
23 // Related to issue #1964
24 fn consume_units_with_for_loop() {
25     // `for_let_unit` lint should not be triggered by consuming them using for loop.
26     let v = vec![(), (), ()];
27     let mut count = 0;
28     for _ in v {
29         count += 1;
30     }
31     assert_eq!(count, 3);
32
33     // Same for consuming from some other Iterator<Item = ()>.
34     let (tx, rx) = ::std::sync::mpsc::channel();
35     tx.send(()).unwrap();
36     drop(tx);
37
38     count = 0;
39     for _ in rx.iter() {
40         count += 1;
41     }
42     assert_eq!(count, 1);
43 }
44
45 #[derive(Copy, Clone)]
46 pub struct ContainsUnit(()); // should be fine