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