1 #![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
2 #![warn(clippy::ptr_arg)]
5 use std::path::PathBuf;
7 fn do_vec(x: &Vec<i64>) {
11 fn do_vec_mut(x: &mut Vec<i64>) {
15 fn do_str(x: &String) {
19 fn do_str_mut(x: &mut String) {
23 fn do_path(x: &PathBuf) {
27 fn do_path_mut(x: &mut PathBuf) {
35 fn do_vec(x: &Vec<i64>);
36 fn do_item(x: &Self::Item);
41 // no error, in trait impl (#425)
44 fn do_vec(x: &Vec<i64>) {}
45 fn do_item(x: &Vec<u8>) {}
48 fn cloned(x: &Vec<u8>) -> Vec<u8> {
50 let f = e.clone(); // OK
57 fn str_cloned(x: &String) -> String {
61 let d = a.clone().clone().clone();
65 fn path_cloned(x: &PathBuf) -> PathBuf {
69 let d = a.clone().clone().clone();
73 fn false_positive_capacity(x: &Vec<u8>, y: &String) {
79 fn false_positive_capacity_too(x: &String) -> String {
80 if x.capacity() > 1024 {
87 fn test_cow_with_ref(c: &Cow<[i32]>) {}
89 fn test_cow(c: Cow<[i32]>) {
97 // no error for &self references where self is of type String (#2293)
98 impl Foo2 for String {
99 fn do_string(&self) {}
102 // Check that the allow attribute on parameters is honored
104 use std::borrow::Cow;
105 use std::path::PathBuf;
108 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
109 #[allow(clippy::ptr_arg)] _s: &String,
110 #[allow(clippy::ptr_arg)] _p: &PathBuf,
111 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
118 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
119 #[allow(clippy::ptr_arg)] _s: &String,
120 #[allow(clippy::ptr_arg)] _p: &PathBuf,
121 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
128 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
129 #[allow(clippy::ptr_arg)] _s: &String,
130 #[allow(clippy::ptr_arg)] _p: &PathBuf,
131 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
138 use std::path::PathBuf;
140 fn foo_vec(vec: &Vec<u8>) {
141 let _ = vec.clone().pop();
142 let _ = vec.clone().clone();
145 fn foo_path(path: &PathBuf) {
146 let _ = path.clone().pop();
147 let _ = path.clone().clone();
150 fn foo_str(str: &PathBuf) {
151 let _ = str.clone().pop();
152 let _ = str.clone().clone();
156 fn mut_vec_slice_methods(v: &mut Vec<u32>) {
157 v.copy_within(1..5, 10);
160 fn mut_vec_vec_methods(v: &mut Vec<u32>) {
164 fn vec_contains(v: &Vec<u32>) -> bool {
165 [vec![], vec![0]].as_slice().contains(v)
168 fn fn_requires_vec(v: &Vec<u32>) -> bool {
172 fn impl_fn_requires_vec(v: &Vec<u32>, f: impl Fn(&Vec<u32>)) {
176 fn dyn_fn_requires_vec(v: &Vec<u32>, f: &dyn Fn(&Vec<u32>)) {
180 // No error for types behind an alias (#7699)
186 fn f(v: &mut Vec<i32>);
187 fn f2(v: &mut Vec<i32>) {}
191 fn two_vecs(a: &mut Vec<u32>, b: &mut Vec<u32>) {