]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/unused_unit.rs
Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyup
[rust.git] / src / tools / clippy / tests / ui / unused_unit.rs
1 // run-rustfix
2
3 // The output for humans should just highlight the whole span without showing
4 // the suggested replacement, but we also want to test that suggested
5 // replacement only removes one set of parentheses, rather than naïvely
6 // stripping away any starting or ending parenthesis characters—hence this
7 // test of the JSON error format.
8
9 #![feature(custom_inner_attributes)]
10 #![feature(closure_lifetime_binder)]
11 #![rustfmt::skip]
12
13 #![deny(clippy::unused_unit)]
14 #![allow(dead_code)]
15 #![allow(clippy::from_over_into)]
16
17 struct Unitter;
18 impl Unitter {
19     #[allow(clippy::no_effect)]
20     pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
21     where G: Fn() -> () {
22         let _y: &dyn Fn() -> () = &f;
23         (); // this should not lint, as it's not in return type position
24     }
25 }
26
27 impl Into<()> for Unitter {
28     #[rustfmt::skip]
29     fn into(self) -> () {
30         ()
31     }
32 }
33
34 trait Trait {
35     fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
36     where
37         G: FnMut() -> (),
38         H: Fn() -> ();
39 }
40
41 impl Trait for Unitter {
42     fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
43     where
44         G: FnMut() -> (),
45         H: Fn() -> () {}
46 }
47
48 fn return_unit() -> () { () }
49
50 #[allow(clippy::needless_return)]
51 #[allow(clippy::never_loop)]
52 #[allow(clippy::unit_cmp)]
53 fn main() {
54     let u = Unitter;
55     assert_eq!(u.get_unit(|| {}, return_unit), u.into());
56     return_unit();
57     loop {
58         break();
59     }
60     return();
61 }
62
63 // https://github.com/rust-lang/rust-clippy/issues/4076
64 fn foo() {
65     macro_rules! foo {
66         (recv($r:expr) -> $res:pat => $body:expr) => {
67             $body
68         }
69     }
70
71     foo! {
72         recv(rx) -> _x => ()
73     }
74 }
75
76 #[rustfmt::skip]
77 fn test()->(){}
78
79 #[rustfmt::skip]
80 fn test2() ->(){}
81
82 #[rustfmt::skip]
83 fn test3()-> (){}
84
85 fn macro_expr() {
86     macro_rules! e {
87         () => (());
88     }
89     e!()
90 }
91
92 mod issue9748 {
93     fn main() {
94         let _ = for<'a> |_: &'a u32| -> () {};
95     }
96 }