1 #![feature(lint_reasons)]
2 #![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
3 #![warn(clippy::ptr_arg)]
6 use std::path::{Path, PathBuf};
8 fn do_vec(x: &Vec<i64>) {
12 fn do_vec_mut(x: &mut Vec<i64>) {
16 fn do_str(x: &String) {
20 fn do_str_mut(x: &mut String) {
24 fn do_path(x: &PathBuf) {
28 fn do_path_mut(x: &mut PathBuf) {
36 fn do_vec(x: &Vec<i64>);
37 fn do_item(x: &Self::Item);
42 // no error, in trait impl (#425)
45 fn do_vec(x: &Vec<i64>) {}
46 fn do_item(x: &Vec<u8>) {}
49 fn cloned(x: &Vec<u8>) -> Vec<u8> {
51 let f = e.clone(); // OK
58 fn str_cloned(x: &String) -> String {
62 let d = a.clone().clone().clone();
66 fn path_cloned(x: &PathBuf) -> PathBuf {
70 let d = a.clone().clone().clone();
74 fn false_positive_capacity(x: &Vec<u8>, y: &String) {
80 fn false_positive_capacity_too(x: &String) -> String {
81 if x.capacity() > 1024 {
88 fn test_cow_with_ref(c: &Cow<[i32]>) {}
90 fn test_cow(c: Cow<[i32]>) {
98 // no error for &self references where self is of type String (#2293)
99 impl Foo2 for String {
100 fn do_string(&self) {}
103 // Check that the allow attribute on parameters is honored
105 use std::borrow::Cow;
106 use std::path::PathBuf;
109 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
110 #[allow(clippy::ptr_arg)] _s: &String,
111 #[allow(clippy::ptr_arg)] _p: &PathBuf,
112 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
113 #[expect(clippy::ptr_arg)] _expect: &Cow<[i32]>,
117 fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec<u32>, _s: &String) {}
122 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
123 #[allow(clippy::ptr_arg)] _s: &String,
124 #[allow(clippy::ptr_arg)] _p: &PathBuf,
125 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
126 #[expect(clippy::ptr_arg)] _expect: &Cow<[i32]>,
133 #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
134 #[allow(clippy::ptr_arg)] _s: &String,
135 #[allow(clippy::ptr_arg)] _p: &PathBuf,
136 #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
137 #[expect(clippy::ptr_arg)] _expect: &Cow<[i32]>,
144 use std::path::PathBuf;
146 fn foo_vec(vec: &Vec<u8>) {
147 let _ = vec.clone().pop();
148 let _ = vec.clone().clone();
151 fn foo_path(path: &PathBuf) {
152 let _ = path.clone().pop();
153 let _ = path.clone().clone();
156 fn foo_str(str: &PathBuf) {
157 let _ = str.clone().pop();
158 let _ = str.clone().clone();
162 fn mut_vec_slice_methods(v: &mut Vec<u32>) {
163 v.copy_within(1..5, 10);
166 fn mut_vec_vec_methods(v: &mut Vec<u32>) {
170 fn vec_contains(v: &Vec<u32>) -> bool {
171 [vec![], vec![0]].as_slice().contains(v)
174 fn fn_requires_vec(v: &Vec<u32>) -> bool {
178 fn impl_fn_requires_vec(v: &Vec<u32>, f: impl Fn(&Vec<u32>)) {
182 fn dyn_fn_requires_vec(v: &Vec<u32>, f: &dyn Fn(&Vec<u32>)) {
186 // No error for types behind an alias (#7699)
192 fn f(v: &mut Vec<i32>);
193 fn f2(v: &mut Vec<i32>) {}
197 fn two_vecs(a: &mut Vec<u32>, b: &mut Vec<u32>) {
205 fn cow_conditional_to_mut(a: &mut Cow<str>) {
207 a.to_mut().push_str("foo");
212 fn dyn_trait_ok(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
214 impl<U> T for Vec<U> {}
216 impl T for PathBuf {}
217 fn takes_dyn(_: &mut dyn T) {}
224 fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
226 impl<U> T for Vec<U> {}
230 impl T for PathBuf {}
232 fn takes_dyn(_: &mut dyn T) {}