-
Notifications
You must be signed in to change notification settings - Fork 0
prototype an example-based approach to explaining the rewrites #1
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the right direction, but I think we're missing key details.
Some users invoke methods on a `dyn Trait` value where the method name overlaps with a new prelude trait: | ||
|
||
```rust | ||
trait Foo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of Foo
for both the trait here and the struct above is confusing. Can we use different names?
|
||
### Fully qualified calls to inherent methods | ||
|
||
Many types define their own inherent methods with the name `from_iter`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we establish that there is a method from_iter
on the FromIter
trait. I think we're requiring the reader to piece too much together here.
} | ||
``` | ||
|
||
Calls like `Foo::from_iter` cannot be confused with calls to `<Foo as FromIter>::from_iter`, because inherent methods take precedence over trait methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think also we should connect the dots for the reader. Something like: "rewriting method calls to use fully qualified syntax ensures that the inherent method will be called".
fn into_iter(&self); | ||
} | ||
fn bar(f: &dyn Foo) { | ||
f.into_iter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would into_iter
mean FromIter::into_iter
? Does Foo
implement FromIter
?
} | ||
``` | ||
|
||
In these cases, the lint will sometimes rewrite to introduce additional dereferences or otherwise clarify the type of the method receiver. This ensures that the `dyn Trait` method is chosen, versus the methods from the prelude trait. For example, `f.into_iter()` above would become `(*f).into_iter()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the dereference make the trait object method call unambiguous?
@rylev these are good comments but I don't know if I'll have time to follow up on them! maybe @jam1garner can land this and then we can continue on the main PR? |
No description provided.