]> 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 8d18d848ae0eeb439af0efe136acbcaf29faaafe..b201e160ebd93e2ac2555372f82442c84afd60f2 100644 (file)
@@ -1,4 +1,11 @@
-#![feature(tool_lints)]
+// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
 
 #![warn(clippy::use_self)]
 #![allow(dead_code)]
@@ -44,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 }
         }
     }
 }
@@ -95,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()
@@ -127,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()
@@ -165,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()
@@ -195,3 +201,52 @@ fn into_bytes(&self) -> Vec<u8> {
         }
     }
 }
+
+mod existential {
+    struct Foo;
+
+    impl Foo {
+        fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
+            foos.iter()
+        }
+
+        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::*;
+        }
+    }
+}