about summary refs log tree commit diff
path: root/src/test/ui/error-codes
diff options
context:
space:
mode:
authorJan Verbeek <jan.verbeek@posteo.nl>2020-10-17 13:36:59 +0200
committerJan Verbeek <jan.verbeek@posteo.nl>2020-10-17 13:36:59 +0200
commite701ae376a040d9f5614cda3be6fabffe884b432 (patch)
treee1a396230ff695c232c17614df18e8e8762788a2 /src/test/ui/error-codes
parent03687f8ffaf5ff03f6bedbe77752b9f930c7efeb (diff)
downloadrust-e701ae376a040d9f5614cda3be6fabffe884b432.tar.gz
rust-e701ae376a040d9f5614cda3be6fabffe884b432.zip
Suggest correct place to add `self` parameter when inside closure
It would incorrectly suggest adding it as a parameter to the closure instead of the
containing function.
Diffstat (limited to 'src/test/ui/error-codes')
-rw-r--r--src/test/ui/error-codes/E0424.rs4
-rw-r--r--src/test/ui/error-codes/E0424.stderr17
2 files changed, 19 insertions, 2 deletions
diff --git a/src/test/ui/error-codes/E0424.rs b/src/test/ui/error-codes/E0424.rs
index fa0c86ecf48..6e531942cad 100644
--- a/src/test/ui/error-codes/E0424.rs
+++ b/src/test/ui/error-codes/E0424.rs
@@ -10,6 +10,10 @@ impl Foo {
     fn baz(_: i32) {
         self.bar(); //~ ERROR E0424
     }
+
+    fn qux() {
+        let _ = || self.bar(); //~ ERROR E0424
+    }
 }
 
 fn main () {
diff --git a/src/test/ui/error-codes/E0424.stderr b/src/test/ui/error-codes/E0424.stderr
index 9b8a29e8272..20b7a4cb6ec 100644
--- a/src/test/ui/error-codes/E0424.stderr
+++ b/src/test/ui/error-codes/E0424.stderr
@@ -24,14 +24,27 @@ help: add a `self` receiver parameter to make the associated `fn` a method
 LL |     fn baz(&self, _: i32) {
    |            ^^^^^^
 
+error[E0424]: expected value, found module `self`
+  --> $DIR/E0424.rs:15:20
+   |
+LL |     fn qux() {
+   |        --- this function doesn't have a `self` parameter
+LL |         let _ = || self.bar();
+   |                    ^^^^ `self` value is a keyword only available in methods with a `self` parameter
+   |
+help: add a `self` receiver parameter to make the associated `fn` a method
+   |
+LL |     fn qux(&self) {
+   |            ^^^^^
+
 error[E0424]: expected unit struct, unit variant or constant, found module `self`
-  --> $DIR/E0424.rs:16:9
+  --> $DIR/E0424.rs:20:9
    |
 LL | fn main () {
    |    ---- this function can't have a `self` parameter
 LL |     let self = "self";
    |         ^^^^ `self` value is a keyword and may not be bound to variables or shadowed
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0424`.