4 clippy::redundant_closure_call,
5 clippy::many_single_char_names,
6 clippy::needless_pass_by_value,
7 clippy::option_map_unit_fn,
8 clippy::trivially_copy_pass_by_ref
11 clippy::redundant_closure,
12 clippy::redundant_closure_for_method_calls,
13 clippy::needless_borrow
16 use std::path::PathBuf;
19 let a = Some(1u8).map(|a| foo(a));
21 let c = Some(1u8).map(|a| {1+2; foo}(a));
22 let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
23 all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
25 Some(1u8).map(|a| unsafe_fn(a)); // unsafe fn
29 let e = Some(1u8).map(|a| divergent(a));
30 let e = Some(1u8).map(|a| generic(a));
31 let e = Some(1u8).map(generic);
33 let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
34 Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
38 fn trait_foo(self) -> bool;
39 fn trait_foo_ref(&self) -> bool;
42 struct TestStruct<'a> {
46 impl<'a> TestStruct<'a> {
47 fn foo(self) -> bool {
50 unsafe fn foo_unsafe(self) -> bool {
55 impl<'a> TestTrait for TestStruct<'a> {
56 fn trait_foo(self) -> bool {
59 fn trait_foo_ref(&self) -> bool {
64 impl<'a> std::ops::Deref for TestStruct<'a> {
66 fn deref(&self) -> &char {
71 fn test_redundant_closures_containing_method_calls() {
73 let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
74 let e = Some(TestStruct { some_ref: &i }).map(TestStruct::foo);
75 let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
76 let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo_ref());
77 let e = Some(TestStruct { some_ref: &i }).map(TestTrait::trait_foo);
78 let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
79 let e = Some(&mut vec![1, 2, 3]).map(std::vec::Vec::clear);
81 let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo_unsafe());
83 let e = Some("str").map(|s| s.to_string());
84 let e = Some("str").map(str::to_string);
85 let e = Some('a').map(|s| s.to_uppercase());
86 let e = Some('a').map(char::to_uppercase);
87 let e: std::vec::Vec<usize> = vec!['a', 'b', 'c'].iter().map(|c| c.len_utf8()).collect();
88 let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
89 let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(char::to_ascii_uppercase).collect();
90 let p = Some(PathBuf::new());
91 let e = p.as_ref().and_then(|s| s.to_str());
92 let c = Some(TestStruct { some_ref: &i })
94 .map(|c| c.to_ascii_uppercase());
96 fn test_different_borrow_levels<T>(t: &[&T])
100 t.iter().filter(|x| x.trait_foo_ref());
101 t.iter().map(|x| x.trait_foo_ref());
114 fn foo2(_: u8) -> u8 {
118 fn all<X, F>(x: &[X], y: &X, f: F) -> bool
120 F: Fn(&X, &X) -> bool,
122 x.iter().all(|e| f(e, y))
125 fn below(x: &u8, y: &u8) -> bool {
129 unsafe fn unsafe_fn(_: u8) {}
131 fn divergent(_: u8) -> ! {
135 fn generic<T>(_: T) -> u8 {