about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/use_self.rs3
-rw-r--r--tests/ui/use_self.fixed10
-rw-r--r--tests/ui/use_self.rs10
-rw-r--r--tests/ui/use_self.stderr20
4 files changed, 38 insertions, 5 deletions
diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs
index a2fc8bcc4a6..903e0a81b99 100644
--- a/clippy_lints/src/use_self.rs
+++ b/clippy_lints/src/use_self.rs
@@ -248,7 +248,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
             | ItemKind::Enum(..)
             | ItemKind::Struct(..)
             | ItemKind::Union(..)
-            | ItemKind::Impl(..) => {
+            | ItemKind::Impl(..)
+            | ItemKind::Fn(..) => {
                 // Don't check statements that shadow `Self` or where `Self` can't be used
             },
             _ => walk_item(self, item),
diff --git a/tests/ui/use_self.fixed b/tests/ui/use_self.fixed
index 5eae9a7a806..730d391848e 100644
--- a/tests/ui/use_self.fixed
+++ b/tests/ui/use_self.fixed
@@ -249,6 +249,16 @@ mod nesting {
                     Self { foo: Foo {} }
                 }
             }
+
+            // Can't use Self here
+            fn baz() -> Foo {
+                Foo {}
+            }
+        }
+
+        // Should lint here
+        fn baz() -> Self {
+            Self {}
         }
     }
 
diff --git a/tests/ui/use_self.rs b/tests/ui/use_self.rs
index 8e28bbbeb9c..00824731512 100644
--- a/tests/ui/use_self.rs
+++ b/tests/ui/use_self.rs
@@ -249,6 +249,16 @@ mod nesting {
                     Bar { foo: Foo {} }
                 }
             }
+
+            // Can't use Self here
+            fn baz() -> Foo {
+                Foo {}
+            }
+        }
+
+        // Should lint here
+        fn baz() -> Foo {
+            Foo {}
         }
     }
 
diff --git a/tests/ui/use_self.stderr b/tests/ui/use_self.stderr
index af9e15edb6c..6e39a28012a 100644
--- a/tests/ui/use_self.stderr
+++ b/tests/ui/use_self.stderr
@@ -151,6 +151,18 @@ LL |         use_self_expand!(); // Should lint in local macros
    |         ------------------- in this macro invocation
 
 error: unnecessary structure name repetition
+  --> $DIR/use_self.rs:260:21
+   |
+LL |         fn baz() -> Foo {
+   |                     ^^^ help: use the applicable keyword: `Self`
+
+error: unnecessary structure name repetition
+  --> $DIR/use_self.rs:261:13
+   |
+LL |             Foo {}
+   |             ^^^ help: use the applicable keyword: `Self`
+
+error: unnecessary structure name repetition
   --> $DIR/use_self.rs:248:29
    |
 LL |                 fn bar() -> Bar {
@@ -163,22 +175,22 @@ LL |                     Bar { foo: Foo {} }
    |                     ^^^ help: use the applicable keyword: `Self`
 
 error: unnecessary structure name repetition
-  --> $DIR/use_self.rs:293:13
+  --> $DIR/use_self.rs:303:13
    |
 LL |             nested::A::fun_1();
    |             ^^^^^^^^^ help: use the applicable keyword: `Self`
 
 error: unnecessary structure name repetition
-  --> $DIR/use_self.rs:294:13
+  --> $DIR/use_self.rs:304:13
    |
 LL |             nested::A::A;
    |             ^^^^^^^^^ help: use the applicable keyword: `Self`
 
 error: unnecessary structure name repetition
-  --> $DIR/use_self.rs:296:13
+  --> $DIR/use_self.rs:306:13
    |
 LL |             nested::A {};
    |             ^^^^^^^^^ help: use the applicable keyword: `Self`
 
-error: aborting due to 29 previous errors
+error: aborting due to 31 previous errors