8000 Refer to "associated functions" instead of "static methods" by estebank · Pull Request #65542 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Refer to "associated functions" instead of "static methods" #65542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review comments: help wording
  • Loading branch information
estebank committed Oct 18, 2019
commit 865c4bcff6b52f69b4122e3a0f02f647cf588553
21 changes: 11 additions & 10 deletions src/librustc_resolve/error_codes.rs
42AF
Original file line number Diff line number Diff line change
Expand Up @@ -1013,30 +1013,31 @@ fn h1() -> i32 {
"##,

E0424: r##"
The `self` keyword was used inside of an associated function instead of inside
of a method. Associated functions have no "`self` receiver" argument, and are
equivalent to regular functions which exist in the namespace of a trait.
Methods, on the other hand, have a `self` reciver argument, like `self`,
`&self`, `&mut self` or `self: &mut Pin<Self>` (this last one is an example of
an ["abitrary `self` type"](https://github.com/rust-lang/rust/issues/44874)).
The `self` keyword was used inside of an associated function without a "`self`
receiver" parameter. The `self` keyword can only be used inside methods, which
are associated functions (functions defined inside of a `trait` or `impl` block)
that have a `self` receiver as its first parameter, like `self`, `&self`,
`&mut self` or `self: &mut Pin<Self>` (this last one is an example of an
["abitrary `self` type"](https://github.com/rust-lang/rust/issues/44874)).

Erroneous code example:

```compile_fail,E0424
struct Foo;

impl Foo {
// `bar` is a method, because it has a receiver argument.
// `bar` is a method, because it has a receiver parameter.
fn bar(&self) {}

// `foo` is an associated function, because it has no receiver argument.
// `foo` is not a method, because it has no receiver parameter.
fn foo() {
self.bar(); // error: `self` is not available in an associated function
self.bar(); // error: `self` value is a keyword only available in
// methods with a `self` parameter
}
}
```

Check if the associated function's argument list should have contained a `self`
Check if the associated function's parameter list should have contained a `self`
receiver for it to be a method, and add it if so. Example:

```
Expand Down
0