1 #![feature(tool_lints)]
4 #![warn(clippy::map_clone)]
6 #![allow(clippy::clone_on_copy, unused)]
12 x.iter().map(|y| y.clone());
18 x.iter().map(|y| { y.clone() });
20 x.iter().map(|&y| { y });
22 x.iter().map(|y| { *y });
24 x.iter().map(Clone::clone);
28 fn map_clone_option() {
30 x.as_ref().map(|y| y.clone());
32 x.as_ref().map(|&y| y);
34 x.as_ref().map(|y| *y);
38 fn not_linted_option() {
41 // Not linted: other statements
47 // Not linted: argument bindings
49 x.map(|(y, _)| y.clone());
51 // Not linted: cloning something else
52 x.map(|y| y.0.clone());
54 // Not linted: no dereferences
57 // Not linted: multiple dereferences
58 let _: Option<(i32, i32)> = x.as_ref().as_ref().map(|&&x| x);
61 #[derive(Copy, Clone)]
64 fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Wrapper<U> {
69 fn map_clone_other() {
71 let x = Wrapper(&eight);
73 // Not linted: not a linted type
79 #[derive(Copy, Clone)]
83 impl Deref for UnusualDeref {
85 fn deref(&self) -> &i32 { &NINE }
88 fn map_clone_deref() {
89 let x = Some(UnusualDeref);
90 let _: Option<UnusualDeref> = x.as_ref().map(|y| *y);
93 // Not linted: using deref conversion
94 let _: Option<i32> = x.map(|y| *y);
96 // Not linted: using regular deref but also deref conversion
97 let _: Option<i32> = x.as_ref().map(|y| **y);
100 // stuff that used to be a false positive
101 fn former_false_positive() {
102 vec![1].iter_mut().map(|x| *x); // #443