]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/useless_asref.rs
Auto merge of #6298 - JohnTitor:fix-example, r=llogiq
[rust.git] / tests / ui / useless_asref.rs
index 8599d67c767d3decdeeab2753eda75211ae1882e..2a80291f5d837b4614de012ac60f9fb1d2b9b256 100644 (file)
@@ -1,12 +1,16 @@
-#![deny(useless_asref)]
+// run-rustfix
+
+#![deny(clippy::useless_asref)]
 
 use std::fmt::Debug;
 
 struct FakeAsRef;
 
-#[allow(should_implement_trait)]
+#[allow(clippy::should_implement_trait)]
 impl FakeAsRef {
-    fn as_ref(&self) -> &Self { self }
+    fn as_ref(&self) -> &Self {
+        self
+    }
 }
 
 struct MoreRef;
@@ -17,14 +21,22 @@ fn as_ref(&self) -> &&'a &'b &'c MoreRef {
     }
 }
 
-fn foo_rstr(x: &str) { println!("{:?}", x); }
-fn foo_rslice(x: &[i32]) { println!("{:?}", x); }
-fn foo_mrslice(x: &mut [i32]) { println!("{:?}", x); }
-fn foo_rrrrmr(_: &&&&MoreRef) { println!("so many refs"); }
+fn foo_rstr(x: &str) {
+    println!("{:?}", x);
+}
+fn foo_rslice(x: &[i32]) {
+    println!("{:?}", x);
+}
+fn foo_mrslice(x: &mut [i32]) {
+    println!("{:?}", x);
+}
+fn foo_rrrrmr(_: &&&&MoreRef) {
+    println!("so many refs");
+}
 
 fn not_ok() {
     let rstr: &str = "hello";
-    let mut mrslice: &mut [i32] = &mut [1,2,3];
+    let mut mrslice: &mut [i32] = &mut [1, 2, 3];
 
     {
         let rslice: &[i32] = &*mrslice;
@@ -55,6 +67,7 @@ fn not_ok() {
         foo_rslice(mrrrrrslice.as_ref());
         foo_rslice(mrrrrrslice);
     }
+    #[allow(unused_parens, clippy::double_parens)]
     foo_rrrrmr((&&&&MoreRef).as_ref());
 
     generic_not_ok(mrslice);
@@ -63,8 +76,8 @@ fn not_ok() {
 
 fn ok() {
     let string = "hello".to_owned();
-    let mut arr = [1,2,3];
-    let mut vec = vec![1,2,3];
+    let mut arr = [1, 2, 3];
+    let mut vec = vec![1, 2, 3];
 
     {
         foo_rstr(string.as_ref());
@@ -97,8 +110,12 @@ fn ok() {
     generic_ok(&mut arr);
 }
 
-fn foo_mrt<T: Debug + ?Sized>(t: &mut T) { println!("{:?}", t); }
-fn foo_rt<T: Debug + ?Sized>(t: &T) { println!("{:?}", t); }
+fn foo_mrt<T: Debug + ?Sized>(t: &mut T) {
+    println!("{:?}", t);
+}
+fn foo_rt<T: Debug + ?Sized>(t: &T) {
+    println!("{:?}", t);
+}
 
 fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
     foo_mrt(mrt.as_mut());