]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/let_unit.fixed
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / let_unit.fixed
CommitLineData
f20569fa
XL
1// run-rustfix
2
3#![warn(clippy::let_unit_value)]
4#![allow(clippy::no_effect)]
5#![allow(unused_variables)]
6
7macro_rules! let_and_return {
8 ($n:expr) => {{
9 let ret = $n;
10 }};
11}
12
13fn main() {
14 println!("x");
15 let _y = 1; // this is fine
16 let _z = ((), 1); // this as well
17 if true {
18 ();
19 }
20
21 consume_units_with_for_loop(); // should be fine as well
22
23 multiline_sugg();
24
25 let_and_return!(()) // should be fine
26}
27
28// Related to issue #1964
29fn consume_units_with_for_loop() {
30 // `for_let_unit` lint should not be triggered by consuming them using for loop.
31 let v = vec![(), (), ()];
32 let mut count = 0;
33 for _ in v {
34 count += 1;
35 }
36 assert_eq!(count, 3);
37
38 // Same for consuming from some other Iterator<Item = ()>.
39 let (tx, rx) = ::std::sync::mpsc::channel();
40 tx.send(()).unwrap();
41 drop(tx);
42
43 count = 0;
44 for _ in rx.iter() {
45 count += 1;
46 }
47 assert_eq!(count, 1);
48}
49
50fn multiline_sugg() {
51 let v: Vec<u8> = vec![2];
52
53 v
54 .into_iter()
55 .map(|i| i * 2)
56 .filter(|i| i % 2 == 0)
57 .map(|_| ())
58 .next()
59 .unwrap();
60}
61
62#[derive(Copy, Clone)]
63pub struct ContainsUnit(()); // should be fine