]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/implicit_clone.rs
1 #![warn(clippy::implicit_clone)]
2 #![allow(clippy::redundant_clone)]
3 use std
::borrow
::Borrow
;
4 use std
::ffi
::{OsStr, OsString}
;
5 use std
::path
::PathBuf
;
7 fn return_owned_from_slice(slice
: &[u32]) -> Vec
<u32> {
11 pub fn own_same
<T
>(v
: T
) -> T
13 T
: ToOwned
<Owned
= T
>,
18 pub fn own_same_from_ref
<T
>(v
: &T
) -> T
20 T
: ToOwned
<Owned
= T
>,
25 pub fn own_different
<T
, U
>(v
: T
) -> U
27 T
: ToOwned
<Owned
= U
>,
32 #[derive(Copy, Clone)]
36 fn to_vec(self) -> Kitten
{
40 impl Borrow
<BorrowedKitten
> for Kitten
{
41 fn borrow(&self) -> &BorrowedKitten
{
42 static VALUE
: BorrowedKitten
= BorrowedKitten {}
;
47 struct BorrowedKitten {}
48 impl ToOwned
for BorrowedKitten
{
50 fn to_owned(&self) -> Kitten
{
56 #[allow(clippy::ptr_arg)]
57 pub fn to_vec(v
: &Vec
<u32>) -> Vec
<u32> {
64 let _
= return_owned_from_slice(&vec
);
65 let _
= vec
.to_owned();
69 let _
= return_owned_from_slice(vec_ref
);
70 let _
= vec_ref
.to_owned();
71 let _
= vec_ref
.to_vec();
73 // we expect no lint for this
74 let _
= weird
::to_vec(&vec
);
76 // we expect no lints for this
77 let slice
: &[u32] = &[1, 2, 3, 4, 5];
78 let _
= return_owned_from_slice(slice
);
79 let _
= slice
.to_owned();
80 let _
= slice
.to_vec();
82 let str = "hello world".to_string();
83 let _
= str.to_owned();
85 // testing w/ an arbitrary type
86 let kitten
= Kitten {}
;
87 let _
= kitten
.to_owned();
88 let _
= own_same_from_ref(&kitten
);
90 let _
= kitten
.to_vec();
92 // we expect no lints for this
93 let borrowed
= BorrowedKitten {}
;
94 let _
= borrowed
.to_owned();
96 let pathbuf
= PathBuf
::new();
97 let _
= pathbuf
.to_owned();
98 let _
= pathbuf
.to_path_buf();
100 let os_string
= OsString
::from("foo");
101 let _
= os_string
.to_owned();
102 let _
= os_string
.to_os_string();
104 // we expect no lints for this
105 let os_str
= OsStr
::new("foo");
106 let _
= os_str
.to_owned();
107 let _
= os_str
.to_os_string();
110 let pathbuf_ref
= &pathbuf
;
111 let pathbuf_ref
= &pathbuf_ref
;
112 let _
= pathbuf_ref
.to_owned(); // Don't lint. Returns `&PathBuf`
113 let _
= pathbuf_ref
.to_path_buf();
114 let pathbuf_ref
= &pathbuf_ref
;
115 let _
= pathbuf_ref
.to_owned(); // Don't lint. Returns `&&PathBuf`
116 let _
= pathbuf_ref
.to_path_buf();