]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/ptr_arg.rs
Merge commit '7ea7cd165ad6705603852771bf82cc2fd6560db5' into clippyup2
[rust.git] / tests / ui / ptr_arg.rs
index e76221355aeaebd305ee6b23c25a5e96780ca754..541225e635102b73626c4c7e960c7796f2161f8f 100644 (file)
@@ -1,6 +1,4 @@
-#![feature(tool_lints)]
-
-#![allow(unused, clippy::many_single_char_names)]
+#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
 #![warn(clippy::ptr_arg)]
 
 use std::borrow::Cow;
@@ -9,7 +7,8 @@ fn do_vec(x: &Vec<i64>) {
     //Nothing here
 }
 
-fn do_vec_mut(x: &mut Vec<i64>) { // no error here
+fn do_vec_mut(x: &mut Vec<i64>) {
+    // no error here
     //Nothing here
 }
 
@@ -17,12 +16,12 @@ fn do_str(x: &String) {
     //Nothing here either
 }
 
-fn do_str_mut(x: &mut String) { // no error here
+fn do_str_mut(x: &mut String) {
+    // no error here
     //Nothing here either
 }
 
-fn main() {
-}
+fn main() {}
 
 trait Foo {
     type Item;
@@ -52,9 +51,7 @@ fn str_cloned(x: &String) -> String {
     let a = x.clone();
     let b = x.clone();
     let c = b.clone();
-    let d = a.clone()
-             .clone()
-             .clone();
+    let d = a.clone().clone().clone();
     x.clone()
 }
 
@@ -65,15 +62,55 @@ fn false_positive_capacity(x: &Vec<u8>, y: &String) {
 }
 
 fn false_positive_capacity_too(x: &String) -> String {
-    if x.capacity() > 1024 { panic!("Too large!"); }
+    if x.capacity() > 1024 {
+        panic!("Too large!");
+    }
     x.clone()
 }
 
 #[allow(dead_code)]
-fn test_cow_with_ref(c: &Cow<[i32]>) {
-}
+fn test_cow_with_ref(c: &Cow<[i32]>) {}
 
-#[allow(dead_code)]
 fn test_cow(c: Cow<[i32]>) {
     let _c = c;
 }
+
+trait Foo2 {
+    fn do_string(&self);
+}
+
+// no error for &self references where self is of type String (#2293)
+impl Foo2 for String {
+    fn do_string(&self) {}
+}
+
+// Check that the allow attribute on parameters is honored
+mod issue_5644 {
+    use std::borrow::Cow;
+
+    fn allowed(
+        #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
+        #[allow(clippy::ptr_arg)] _s: &String,
+        #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
+    ) {
+    }
+
+    struct S {}
+    impl S {
+        fn allowed(
+            #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
+            #[allow(clippy::ptr_arg)] _s: &String,
+            #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
+        ) {
+        }
+    }
+
+    trait T {
+        fn allowed(
+            #[allow(clippy::ptr_arg)] _v: &Vec<u32>,
+            #[allow(clippy::ptr_arg)] _s: &String,
+            #[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
+        ) {
+        }
+    }
+}