]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/use_self.fixed
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
[rust.git] / tests / ui / use_self.fixed
index 5eae9a7a8069dba541cfe9b18d19e66706efc703..ebb3aa28daf3d80d0cbc862b80e88aa22b07034e 100644 (file)
@@ -1,4 +1,5 @@
 // run-rustfix
+// edition:2018
 
 #![warn(clippy::use_self)]
 #![allow(dead_code)]
@@ -68,120 +69,6 @@ mod lifetimes {
     }
 }
 
-#[allow(clippy::boxed_local)]
-mod traits {
-
-    use std::ops::Mul;
-
-    trait SelfTrait {
-        fn refs(p1: &Self) -> &Self;
-        fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
-        fn mut_refs(p1: &mut Self) -> &mut Self;
-        fn nested(p1: Box<Self>, p2: (&u8, &Self));
-        fn vals(r: Self) -> Self;
-    }
-
-    #[derive(Default)]
-    struct Bad;
-
-    impl SelfTrait for Bad {
-        fn refs(p1: &Self) -> &Self {
-            p1
-        }
-
-        fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
-            p1
-        }
-
-        fn mut_refs(p1: &mut Self) -> &mut Self {
-            p1
-        }
-
-        fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
-
-        fn vals(_: Self) -> Self {
-            Self::default()
-        }
-    }
-
-    impl Mul for Bad {
-        type Output = Self;
-
-        fn mul(self, rhs: Self) -> Self {
-            rhs
-        }
-    }
-
-    #[derive(Default)]
-    struct Good;
-
-    impl SelfTrait for Good {
-        fn refs(p1: &Self) -> &Self {
-            p1
-        }
-
-        fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
-            p1
-        }
-
-        fn mut_refs(p1: &mut Self) -> &mut Self {
-            p1
-        }
-
-        fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
-
-        fn vals(_: Self) -> Self {
-            Self::default()
-        }
-    }
-
-    impl Mul for Good {
-        type Output = Self;
-
-        fn mul(self, rhs: Self) -> Self {
-            rhs
-        }
-    }
-
-    trait NameTrait {
-        fn refs(p1: &u8) -> &u8;
-        fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
-        fn mut_refs(p1: &mut u8) -> &mut u8;
-        fn nested(p1: Box<u8>, p2: (&u8, &u8));
-        fn vals(p1: u8) -> u8;
-    }
-
-    // Using `Self` instead of the type name is OK
-    impl NameTrait for u8 {
-        fn refs(p1: &Self) -> &Self {
-            p1
-        }
-
-        fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
-            p1
-        }
-
-        fn mut_refs(p1: &mut Self) -> &mut Self {
-            p1
-        }
-
-        fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
-
-        fn vals(_: Self) -> Self {
-            Self::default()
-        }
-    }
-
-    // Check that self arg isn't linted
-    impl Clone for Good {
-        fn clone(&self) -> Self {
-            // Note: Not linted and it wouldn't be valid
-            // because "can't use `Self` as a constructor`"
-            Good
-        }
-    }
-}
-
 mod issue2894 {
     trait IntoBytes {
         fn into_bytes(&self) -> Vec<u8>;
@@ -239,6 +126,7 @@ mod nesting {
     struct Foo {}
     impl Foo {
         fn foo() {
+            #[allow(unused_imports)]
             use self::Foo; // Can't use Self here
             struct Bar {
                 foo: Foo, // Foo != Self
@@ -249,11 +137,23 @@ mod nesting {
                     Self { foo: Foo {} }
                 }
             }
+
+            // Can't use Self here
+            fn baz() -> Foo {
+                Foo {}
+            }
+        }
+
+        // Should lint here
+        fn baz() -> Self {
+            Self {}
         }
     }
 
     enum Enum {
         A,
+        B(u64),
+        C { field: bool },
     }
     impl Enum {
         fn method() {
@@ -261,6 +161,12 @@ mod nesting {
             use self::Enum::*; // Issue 3425
             static STATIC: Enum = Enum::A; // Can't use Self as type
         }
+
+        fn method2() {
+            let _ = Self::B(42);
+            let _ = Self::C { field: true };
+            let _ = Self::A;
+        }
     }
 }
 
@@ -297,3 +203,51 @@ mod rustfix {
         }
     }
 }
+
+mod issue3567 {
+    struct TestStruct {}
+    impl TestStruct {
+        fn from_something() -> Self {
+            Self {}
+        }
+    }
+
+    trait Test {
+        fn test() -> TestStruct;
+    }
+
+    impl Test for TestStruct {
+        fn test() -> TestStruct {
+            Self::from_something()
+        }
+    }
+}
+
+mod paths_created_by_lowering {
+    use std::ops::Range;
+
+    struct S {}
+
+    impl S {
+        const A: usize = 0;
+        const B: usize = 1;
+
+        async fn g() -> Self {
+            Self {}
+        }
+
+        fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
+            &p[Self::A..Self::B]
+        }
+    }
+
+    trait T {
+        fn f<'a>(&self, p: &'a [u8]) -> &'a [u8];
+    }
+
+    impl T for Range<u8> {
+        fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
+            &p[0..1]
+        }
+    }
+}