forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#66913 - VirrageS:help-self, r=varkor,Centril
Suggest calling method when first argument is `self` Closes: rust-lang#66782 I've explored different approaches for this MR but I think the most straightforward is the best one. I've tried to find out if the methods for given type exist (to maybe have a better suggestion), but we don't collect them anywhere and collecting them is quite problematic. Moreover, collecting all the methods would require rewriting big part of the code and also could potentially include performance degradation, which I don't think is necessary for this simple case.
- Loading branch information
Showing
4 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
struct Foo {} | ||
|
||
impl Foo { | ||
fn foo(&self) { | ||
bar(self); | ||
//~^ ERROR cannot find function `bar` in this scope | ||
//~| HELP try calling `bar` as a method | ||
|
||
bar(&&self, 102); | ||
//~^ ERROR cannot find function `bar` in this scope | ||
//~| HELP try calling `bar` as a method | ||
|
||
bar(&mut self, 102, &"str"); | ||
//~^ ERROR cannot find function `bar` in this scope | ||
//~| HELP try calling `bar` as a method | ||
|
||
bar(); | ||
//~^ ERROR cannot find function `bar` in this scope | ||
|
||
self.bar(); | ||
//~^ ERROR no method named `bar` found for type | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
error[E0425]: cannot find function `bar` in this scope | ||
--> $DIR/suggest-self-2.rs:5:9 | ||
| | ||
LL | bar(self); | ||
| ^^^------ | ||
| | | ||
| help: try calling `bar` as a method: `self.bar()` | ||
|
||
error[E0425]: cannot find function `bar` in this scope | ||
--> $DIR/suggest-self-2.rs:9:9 | ||
| | ||
LL | bar(&&self, 102); | ||
| ^^^------------- | ||
| | | ||
| help: try calling `bar` as a method: `self.bar(102)` | ||
|
||
error[E0425]: cannot find function `bar` in this scope | ||
--> $DIR/suggest-self-2.rs:13:9 | ||
| | ||
LL | bar(&mut self, 102, &"str"); | ||
| ^^^------------------------ | ||
| | | ||
| help: try calling `bar` as a method: `self.bar(102, &"str")` | ||
|
||
error[E0425]: cannot find function `bar` in this scope | ||
--> $DIR/suggest-self-2.rs:17:9 | ||
| | ||
LL | bar(); | ||
| ^^^ not found in this scope | ||
|
||
error[E0599]: no method named `bar` found for type `&Foo` in the current scope | ||
--> $DIR/suggest-self-2.rs:20:14 | ||
| | ||
LL | self.bar(); | ||
| ^^^ method not found in `&Foo` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0425, E0599. | ||
For more information about an error, try `rustc --explain E0425`. |