]> git.lizzy.rs Git - rust.git/blob - tests/ui/eta.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / eta.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![allow(
11     unused,
12     clippy::no_effect,
13     clippy::redundant_closure_call,
14     clippy::many_single_char_names,
15     clippy::needless_pass_by_value,
16     clippy::option_map_unit_fn,
17     clippy::trivially_copy_pass_by_ref
18 )]
19 #![warn(clippy::redundant_closure, clippy::needless_borrow)]
20
21 fn main() {
22     let a = Some(1u8).map(|a| foo(a));
23     meta(|a| foo(a));
24     let c = Some(1u8).map(|a| {1+2; foo}(a));
25     let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
26     all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
27     unsafe {
28         Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
29     }
30
31     // See #815
32     let e = Some(1u8).map(|a| divergent(a));
33     let e = Some(1u8).map(|a| generic(a));
34     let e = Some(1u8).map(generic);
35     // See #515
36     let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
37         Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
38 }
39
40 fn meta<F>(f: F)
41 where
42     F: Fn(u8),
43 {
44     f(1u8)
45 }
46
47 fn foo(_: u8) {}
48
49 fn foo2(_: u8) -> u8 {
50     1u8
51 }
52
53 fn all<X, F>(x: &[X], y: &X, f: F) -> bool
54 where
55     F: Fn(&X, &X) -> bool,
56 {
57     x.iter().all(|e| f(e, y))
58 }
59
60 fn below(x: &u8, y: &u8) -> bool {
61     x < y
62 }
63
64 unsafe fn unsafe_fn(_: u8) {}
65
66 fn divergent(_: u8) -> ! {
67     unimplemented!()
68 }
69
70 fn generic<T>(_: T) -> u8 {
71     0
72 }