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