]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/use_self.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / use_self.rs
index 073d64d5a4bf34aa943a0bab7e8b18b6d1af8eaa..b201e160ebd93e2ac2555372f82442c84afd60f2 100644 (file)
@@ -7,9 +7,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-
-
-
 #![warn(clippy::use_self)]
 #![allow(dead_code)]
 #![allow(clippy::should_implement_trait)]
@@ -54,24 +51,26 @@ fn default() -> Self {
     }
 }
 
-//todo the lint does not handle lifetimed struct
-//the following module should trigger the lint on the third method only
 mod lifetimes {
-    struct Foo<'a>{foo_str: &'a str}
+    struct Foo<'a> {
+        foo_str: &'a str,
+    }
 
     impl<'a> Foo<'a> {
-        // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>`
+        // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
+        // Foo<'b>`
         fn foo(s: &str) -> Foo {
             Foo { foo_str: s }
         }
         // cannot replace with `Self`, because that's `Foo<'a>`
         fn bar() -> Foo<'static> {
-            Foo { foo_str: "foo"}
+            Foo { foo_str: "foo" }
         }
 
-        // `Self` is applicable here
+        // FIXME: the lint does not handle lifetimed struct
+        // `Self` should be applicable here
         fn clone(&self) -> Foo<'a> {
-            Foo {foo_str: self.foo_str}
+            Foo { foo_str: self.foo_str }
         }
     }
 }
@@ -105,8 +104,7 @@ fn mut_refs(p1: &mut Bad) -> &mut Bad {
             p1
         }
 
-        fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {
-        }
+        fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
 
         fn vals(_: Bad) -> Bad {
             Bad::default()
@@ -137,8 +135,7 @@ fn mut_refs(p1: &mut Self) -> &mut Self {
             p1
         }
 
-        fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {
-        }
+        fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
 
         fn vals(_: Self) -> Self {
             Self::default()
@@ -175,8 +172,7 @@ fn mut_refs(p1: &mut Self) -> &mut Self {
             p1
         }
 
-        fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {
-        }
+        fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
 
         fn vals(_: Self) -> Self {
             Self::default()
@@ -210,12 +206,47 @@ mod existential {
     struct Foo;
 
     impl Foo {
-        fn bad(foos: &[Self]) -> impl Iterator<Item=&Foo> {
+        fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
             foos.iter()
         }
 
-        fn good(foos: &[Self]) -> impl Iterator<Item=&Self> {
+        fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
             foos.iter()
         }
     }
 }
+
+mod tuple_structs {
+    pub struct TS(i32);
+
+    impl TS {
+        pub fn ts() -> Self {
+            TS(0)
+        }
+    }
+}
+
+mod issue3410 {
+
+    struct A;
+    struct B;
+
+    trait Trait<T> {
+        fn a(v: T);
+    }
+
+    impl Trait<Vec<A>> for Vec<B> {
+        fn a(_: Vec<A>) {}
+    }
+}
+
+mod issue3425 {
+    enum Enum {
+        A,
+    }
+    impl Enum {
+        fn a() {
+            use self::Enum::*;
+        }
+    }
+}