]> git.lizzy.rs Git - rust.git/blob - tests/ui/unused_unit.rs
Auto merge of #4595 - rust-lang:rustbot, r=flip1995
[rust.git] / 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 #![rustfmt::skip]
11
12 #![deny(clippy::unused_unit)]
13 #![allow(dead_code)]
14
15 struct Unitter;
16 impl Unitter {
17     // try to disorient the lint with multiple unit returns and newlines
18     #[allow(clippy::no_effect)]
19     pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
20         ()
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 fn return_unit() -> () { () }
35
36 #[allow(clippy::needless_return)]
37 #[allow(clippy::never_loop)]
38 #[allow(clippy::unit_cmp)]
39 fn main() {
40     let u = Unitter;
41     assert_eq!(u.get_unit(|| {}, return_unit), u.into());
42     return_unit();
43     loop {
44         break();
45     }
46     return();
47 }
48
49 // https://github.com/rust-lang/rust-clippy/issues/4076
50 fn foo() {
51     macro_rules! foo {
52         (recv($r:expr) -> $res:pat => $body:expr) => {
53             $body
54         }
55     }
56
57     foo! {
58         recv(rx) -> _x => ()
59     }
60 }