diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-10-18 04:11:11 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-18 04:11:11 +0900 |
| commit | 57e38dd4fbd45483c0bb0a7569c97a7031114664 (patch) | |
| tree | 15048e0a1d8d1d3c5d697df8557a36c5cb593a98 /src | |
| parent | 407bba4676064e726acf006235134c849de2e328 (diff) | |
| parent | e701ae376a040d9f5614cda3be6fabffe884b432 (diff) | |
Rollup merge of #78048 - blyxxyz:e0424-improve-self-placement, r=lcnr
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. [For example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1936bcd1e5f981573386e0cee985c3c0): ``` help: add a `self` receiver parameter to make the associated `fn` a method | 5 | let _ = || self&self; | ^^^^^ ``` `DiagnosticMetadata.current_function` is only used for these messages so tweaking its behavior should be ok.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/error-codes/E0424.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/error-codes/E0424.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-5099.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-5099.stderr | 17 |
4 files changed, 38 insertions, 3 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`. diff --git a/src/test/ui/issues/issue-5099.rs b/src/test/ui/issues/issue-5099.rs index ee134835c37..b5abccb4b19 100644 --- a/src/test/ui/issues/issue-5099.rs +++ b/src/test/ui/issues/issue-5099.rs @@ -5,6 +5,9 @@ trait B <A> { fn b(x: i32) { this.b(x); //~ ERROR cannot find value `this` in this scope } + fn c() { + let _ = || this.a; //~ ERROR cannot find value `this` in this scope + } } fn main() {} diff --git a/src/test/ui/issues/issue-5099.stderr b/src/test/ui/issues/issue-5099.stderr index b52fd28b2b5..b39c4a9f272 100644 --- a/src/test/ui/issues/issue-5099.stderr +++ b/src/test/ui/issues/issue-5099.stderr @@ -28,6 +28,21 @@ help: if you meant to use `self`, you are also missing a `self` receiver argumen LL | fn b(&self, x: i32) { | ^^^^^^ -error: aborting due to 2 previous errors +error[E0425]: cannot find value `this` in this scope + --> $DIR/issue-5099.rs:9:20 + | +LL | let _ = || this.a; + | ^^^^ not found in this scope + | +help: you might have meant to use `self` here instead + | +LL | let _ = || self.a; + | ^^^^ +help: if you meant to use `self`, you are also missing a `self` receiver argument + | +LL | fn c(&self) { + | ^^^^^ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0425`. |
