about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-05-05 15:43:03 +0200
committerGitHub <noreply@github.com>2022-05-05 15:43:03 +0200
commit34bf620ac9fba1f5cfb81b09b0c41147b3b97362 (patch)
tree30e1b2ceeb29dbf4aa89aee9908f4916f0e51bb8 /src
parent3f07303efe91442cad38f4a62ed047a7041b9f82 (diff)
parentdf2518955275c3a912dda8951a570abd2daddac4 (diff)
Rollup merge of #96507 - TaKO8Ki:suggest-calling-associated-function, r=lcnr
Suggest calling `Self::associated_function()`

closes #96453
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/resolve/issue-2356.stderr10
-rw-r--r--src/test/ui/suggestions/assoc_fn_without_self.rs20
-rw-r--r--src/test/ui/suggestions/assoc_fn_without_self.stderr37
3 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/resolve/issue-2356.stderr b/src/test/ui/resolve/issue-2356.stderr
index d1872673885..b8d528efc15 100644
--- a/src/test/ui/resolve/issue-2356.stderr
+++ b/src/test/ui/resolve/issue-2356.stderr
@@ -48,6 +48,11 @@ error[E0425]: cannot find function `static_method` in this scope
    |
 LL |         static_method();
    |         ^^^^^^^^^^^^^ not found in this scope
+   |
+help: consider using the associated function
+   |
+LL |         Self::static_method();
+   |         ~~~~~~~~~~~~~~~~~~~
 
 error[E0425]: cannot find function `purr` in this scope
   --> $DIR/issue-2356.rs:54:9
@@ -85,6 +90,11 @@ error[E0425]: cannot find function `grow_older` in this scope
    |
 LL |     grow_older();
    |     ^^^^^^^^^^ not found in this scope
+   |
+help: consider using the associated function
+   |
+LL |     Self::grow_older();
+   |     ~~~~~~~~~~~~~~~~
 
 error[E0425]: cannot find function `shave` in this scope
   --> $DIR/issue-2356.rs:74:5
diff --git a/src/test/ui/suggestions/assoc_fn_without_self.rs b/src/test/ui/suggestions/assoc_fn_without_self.rs
new file mode 100644
index 00000000000..778d9847773
--- /dev/null
+++ b/src/test/ui/suggestions/assoc_fn_without_self.rs
@@ -0,0 +1,20 @@
+fn main() {}
+
+struct S;
+
+impl S {
+    fn foo() {}
+
+    fn bar(&self) {}
+
+    fn baz(a: u8, b: u8) {}
+
+    fn b() {
+        fn c() {
+            foo(); //~ ERROR cannot find function `foo` in this scope
+        }
+        foo(); //~ ERROR cannot find function `foo` in this scope
+        bar(); //~ ERROR cannot find function `bar` in this scope
+        baz(2, 3); //~ ERROR cannot find function `baz` in this scope
+    }
+}
diff --git a/src/test/ui/suggestions/assoc_fn_without_self.stderr b/src/test/ui/suggestions/assoc_fn_without_self.stderr
new file mode 100644
index 00000000000..4a0e62e7309
--- /dev/null
+++ b/src/test/ui/suggestions/assoc_fn_without_self.stderr
@@ -0,0 +1,37 @@
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/assoc_fn_without_self.rs:14:13
+   |
+LL |             foo();
+   |             ^^^ not found in this scope
+
+error[E0425]: cannot find function `foo` in this scope
+  --> $DIR/assoc_fn_without_self.rs:16:9
+   |
+LL |         foo();
+   |         ^^^ not found in this scope
+   |
+help: consider using the associated function
+   |
+LL |         Self::foo();
+   |         ~~~~~~~~~
+
+error[E0425]: cannot find function `bar` in this scope
+  --> $DIR/assoc_fn_without_self.rs:17:9
+   |
+LL |         bar();
+   |         ^^^ not found in this scope
+
+error[E0425]: cannot find function `baz` in this scope
+  --> $DIR/assoc_fn_without_self.rs:18:9
+   |
+LL |         baz(2, 3);
+   |         ^^^ not found in this scope
+   |
+help: consider using the associated function
+   |
+LL |         Self::baz(2, 3);
+   |         ~~~~~~~~~
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0425`.