-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest calling associated
fn
inside trait
s
When calling a function that doesn't exist inside of a trait's associated `fn`, and another associated `fn` in that trait has that name, suggest calling it with the appropriate fully-qualified path. Expand the label to be more descriptive. Prompted by the following user experience: https://users.rust-lang.org/t/cannot-find-function/50663
- Loading branch information
Showing
9 changed files
with
124 additions
and
49 deletions.
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,32 @@ | ||
struct S; | ||
impl Foo for S { | ||
fn parse(s:&str) { | ||
for c in s.chars() { | ||
match c { | ||
'0'..='9' => collect_primary(&c), //~ ERROR cannot find function `collect_primary` | ||
//~^ HELP you might have meant to call the associated function | ||
'+' | '-' => println!("We got a sign: {}", c), | ||
_ => println!("Not a number!") | ||
} | ||
} | ||
} | ||
} | ||
trait Foo { | ||
fn collect_primary(ch:&char) { } | ||
fn parse(s:&str); | ||
} | ||
trait Bar { | ||
fn collect_primary(ch:&char) { } | ||
fn parse(s:&str) { | ||
for c in s.chars() { | ||
match c { | ||
'0'..='9' => collect_primary(&c), //~ ERROR cannot find function `collect_primary` | ||
//~^ HELP you might have meant to call the associated function | ||
'+' | '-' => println!("We got a sign: {}", c), | ||
_ => println!("Not a number!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
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,15 @@ | ||
error[E0425]: cannot find function `collect_primary` in this scope | ||
--> $DIR/associated-fn-called-as-fn.rs:6:30 | ||
| | ||
LL | '0'..='9' => collect_primary(&c), | ||
| ^^^^^^^^^^^^^^^ help: you might have meant to call the associated function: `Self::collect_primary` | ||
|
||
error[E0425]: cannot find function `collect_primary` in this scope | ||
--> $DIR/associated-fn-called-as-fn.rs:23:30 | ||
| | ||
LL | '0'..='9' => collect_primary(&c), | ||
| ^^^^^^^^^^^^^^^ help: you might have meant to call the associated function: `Self::collect_primary` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
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
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