]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/unused_unit.fixed
Auto merge of #80115 - tgnottingham:specialize_opaque_u8_sequences, r=oli-obk
[rust.git] / src / tools / clippy / tests / ui / unused_unit.fixed
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 #![rustfmt::skip]
11
12 #![deny(clippy::unused_unit)]
13 #![allow(dead_code)]
14
15 struct Unitter;
16 impl Unitter {
17     #[allow(clippy::no_effect)]
18     pub fn get_unit<F: Fn(), G>(&self, f: F, _g: G)
19     where G: Fn() {
20         let _y: &dyn Fn() = &f;
21         (); // this should not lint, as it's not in return type position
22     }
23 }
24
25 impl Into<()> for Unitter {
26     #[rustfmt::skip]
27     fn into(self) {
28         
29     }
30 }
31
32 trait Trait {
33     fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
34     where
35         G: FnMut(),
36         H: Fn();
37 }
38
39 impl Trait for Unitter {
40     fn redundant<F: FnOnce(), G, H>(&self, _f: F, _g: G, _h: H)
41     where
42         G: FnMut(),
43         H: Fn() {}
44 }
45
46 fn return_unit() {  }
47
48 #[allow(clippy::needless_return)]
49 #[allow(clippy::never_loop)]
50 #[allow(clippy::unit_cmp)]
51 fn main() {
52     let u = Unitter;
53     assert_eq!(u.get_unit(|| {}, return_unit), u.into());
54     return_unit();
55     loop {
56         break;
57     }
58     return;
59 }
60
61 // https://github.com/rust-lang/rust-clippy/issues/4076
62 fn foo() {
63     macro_rules! foo {
64         (recv($r:expr) -> $res:pat => $body:expr) => {
65             $body
66         }
67     }
68
69     foo! {
70         recv(rx) -> _x => ()
71     }
72 }
73
74 #[rustfmt::skip]
75 fn test(){}
76
77 #[rustfmt::skip]
78 fn test2(){}
79
80 #[rustfmt::skip]
81 fn test3(){}