3 #![feature(lint_reasons)]
4 #![warn(clippy::let_unit_value)]
5 #![allow(unused, clippy::no_effect, clippy::needless_late_init, path_statements)]
7 macro_rules! let_and_return {
15 let _y = 1; // this is fine
16 let _z = ((), 1); // this as well
21 consume_units_with_for_loop(); // should be fine as well
25 let_and_return!(()) // should be fine
28 // Related to issue #1964
29 fn consume_units_with_for_loop() {
30 // `for_let_unit` lint should not be triggered by consuming them using for loop.
31 let v = vec![(), (), ()];
38 // Same for consuming from some other Iterator<Item = ()>.
39 let (tx, rx) = ::std::sync::mpsc::channel();
51 let v: Vec<u8> = vec![2];
56 .filter(|i| i % 2 == 0)
62 #[derive(Copy, Clone)]
63 pub struct ContainsUnit(()); // should be fine
65 fn _returns_generic() {
69 fn f2<T, U>(_: T) -> U {
75 fn f5<T: Default>(x: bool) -> Option<T> {
76 x.then(|| T::default())
79 let _: () = f(); // Ok
80 let _: () = f(); // Lint.
82 let _: () = f2(0i32); // Ok
83 let _: () = f2(0i32); // Lint.
89 // fn f4<T>(mut x: Vec<T>) -> T {
92 // let _: () = f4(vec![()]);
93 // let x: () = f4(vec![()]);
101 let _: () = if true { f() } else { f2(0) }; // Ok
102 let _: () = if true { f() } else { f2(0) }; // Lint
105 let _: () = match Some(0) {
120 let _: () = f5(true).unwrap();
122 #[allow(clippy::let_unit_value)]
156 #[warn(clippy::let_unit_value)]
173 #[allow(clippy::let_unit_value)]
175 #[expect(clippy::let_unit_value)]