2 #![warn(clippy::implicit_clone)]
3 #![allow(clippy::clone_on_copy, clippy::redundant_clone)]
4 use std::borrow::Borrow;
5 use std::ffi::{OsStr, OsString};
6 use std::path::PathBuf;
8 fn return_owned_from_slice(slice: &[u32]) -> Vec<u32> {
12 pub fn own_same<T>(v: T) -> T
14 T: ToOwned<Owned = T>,
19 pub fn own_same_from_ref<T>(v: &T) -> T
21 T: ToOwned<Owned = T>,
26 pub fn own_different<T, U>(v: T) -> U
28 T: ToOwned<Owned = U>,
33 #[derive(Copy, Clone)]
37 fn to_vec(self) -> Kitten {
41 impl Borrow<BorrowedKitten> for Kitten {
42 fn borrow(&self) -> &BorrowedKitten {
43 static VALUE: BorrowedKitten = BorrowedKitten {};
48 struct BorrowedKitten;
49 impl ToOwned for BorrowedKitten {
51 fn to_owned(&self) -> Kitten {
57 #[allow(clippy::ptr_arg)]
58 pub fn to_vec(v: &Vec<u32>) -> Vec<u32> {
65 let _ = return_owned_from_slice(&vec);
66 let _ = vec.to_owned();
70 let _ = return_owned_from_slice(vec_ref);
71 let _ = vec_ref.to_owned();
72 let _ = vec_ref.to_vec();
74 // we expect no lint for this
75 let _ = weird::to_vec(&vec);
77 // we expect no lints for this
78 let slice: &[u32] = &[1, 2, 3, 4, 5];
79 let _ = return_owned_from_slice(slice);
80 let _ = slice.to_owned();
81 let _ = slice.to_vec();
83 let str = "hello world".to_string();
84 let _ = str.to_owned();
86 // testing w/ an arbitrary type
87 let kitten = Kitten {};
88 let _ = kitten.to_owned();
89 let _ = own_same_from_ref(&kitten);
91 let _ = kitten.to_vec();
93 // we expect no lints for this
94 let borrowed = BorrowedKitten {};
95 let _ = borrowed.to_owned();
97 let pathbuf = PathBuf::new();
98 let _ = pathbuf.to_owned();
99 let _ = pathbuf.to_path_buf();
101 let os_string = OsString::from("foo");
102 let _ = os_string.to_owned();
103 let _ = os_string.to_os_string();
105 // we expect no lints for this
106 let os_str = OsStr::new("foo");
107 let _ = os_str.to_owned();
108 let _ = os_str.to_os_string();
111 let pathbuf_ref = &pathbuf;
112 let pathbuf_ref = &pathbuf_ref;
113 let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf`
114 let _ = pathbuf_ref.to_path_buf();
115 let pathbuf_ref = &pathbuf_ref;
116 let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf`
117 let _ = pathbuf_ref.to_path_buf();