Skip to content

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

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

nikomatsakis
Copy link

No description provided.

Copy link

@rylev rylev left a 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 {
Copy link

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`:
Copy link

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.
Copy link

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();
Copy link

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()`.
Copy link

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?

@nikomatsakis
Copy link
Author

@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?

@jam1garner jam1garner merged commit 8dd83cc into jam1garner:master Jul 9, 2021
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

Successfully merging this pull request may close these issues.

3 participants