Skip to content
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

Small mistake in method call expressions explanation? #718

Open
LukasKalbertodt opened this issue Nov 16, 2019 · 4 comments
Open

Small mistake in method call expressions explanation? #718

LukasKalbertodt opened this issue Nov 16, 2019 · 4 comments

Comments

@LukasKalbertodt
Copy link
Member

Here it says:

Then, for each candidate type T, search for a visible method with a receiver of that type in the following places:

  1. T's inherent methods (methods implemented directly on T).
  2. [...]

The part "methods implemented directly on T" is not completely correct, I think. As first sentence already says, we are searching for methods with the receiver type T, not methods in an impl block for T. And those two types can obviously be different.

impl Foo {
    fn by_ref(&self) {}
}

Suppose our candidate type T is &Foo, then by_ref would be a "visible method with a receiver of that type". However, the method by_ref is not implemented on &Foo, but on Foo. In other words: Self in that method is Foo, not &Foo.

To fix this, I would replace "methods implemented directly on T" with: "methods that belong to a type and not to a trait". Or something like that.

Am I correct that the current phrasing is wrong/very misleading? Or am I missing something?

@Havvy

This comment has been minimized.

@LukasKalbertodt

This comment has been minimized.

@Havvy
Copy link
Contributor

Havvy commented Nov 16, 2019

Oh, I see. I was mistaken on what you meant. The real question is what does "methods implemented directly on T" mean? It could be taken in two ways:

  1. The way you're doing it and applying it to what is the type after the impl.
  2. The way the author intended it and applying it to the receiver of the method (e.g. fn (&self) is a method directly implemented for &T)

@LukasKalbertodt
Copy link
Member Author

Yes, exactly. I assume the author just wanted to explain that "inherent method" means that the method does not belong to a trait but is implemented on a type directly. But using T in that explanation is confusing I think (because, as you said, one could interpret this in two ways).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants