]> git.lizzy.rs Git - rust.git/blob - tests/ui/unused_unit.rs
Auto merge of #3645 - phansch:remove_copyright_headers, r=oli-obk
[rust.git] / tests / ui / unused_unit.rs
1 // compile-pass
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 #![deny(clippy::unused_unit)]
10 #![allow(clippy::needless_return)]
11
12 struct Unitter;
13 impl Unitter {
14     // try to disorient the lint with multiple unit returns and newlines
15     pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
16         ()
17     where G: Fn() -> () {
18         let _y: &Fn() -> () = &f;
19         (); // this should not lint, as it's not in return type position
20     }
21 }
22
23 impl Into<()> for Unitter {
24     #[rustfmt::skip]
25     fn into(self) -> () {
26         ()
27     }
28 }
29
30 fn return_unit() -> () { () }
31
32 fn main() {
33     let u = Unitter;
34     assert_eq!(u.get_unit(|| {}, return_unit), u.into());
35     return_unit();
36     loop {
37         break();
38     }
39     return();
40 }