Skip to content

new lint: inherent methods that should be trait impls (fixes #218) #228

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
Aug 27, 2015

Conversation

birkenfeld
Copy link
Contributor

No description provided.

}

impl SelfKind {
fn check(&self, slf: &ExplicitSelf_) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps 'matches' instead of 'check'?

@birkenfeld
Copy link
Contributor Author

Addressed review comments and added quite a few more traits/methods.

@llogiq
Copy link
Contributor

llogiq commented Aug 24, 2015

There's still my comment from an hour ago, I think the lint should not fire if the trait is already implemented.

Otherwise LGTM.

@birkenfeld
Copy link
Contributor Author

There's still my comment from an hour ago, I think the lint should not fire if the trait is already implemented.

I thought you asked for the test I added. Other than that, I don't know what you mean.

impl T {
fn add(self, other: T) -> T { self } //~ERROR defining a method called `add`
fn drop(&mut self) { } //~ERROR defining a method called `drop`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a fn mul(self, other: T) -> T { self } // no error, because trait impl exists here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. But does that make any sense? Now you have defined two mul methods for the type, one of which is used for * and one for explicit .mul() calls. Is there a use case for this?

I know this can't be disallowed by the compiler, since it doesn't know about all the trait impls when compiling a crate, but I wouldn't add extra complexity to the lint just to not warn on a case that should not be written anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should warn, but it should be a different warning, namely that it has both a .mul(_) method and a Mul impl and that may confuse users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that does not belong to this lint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's an acceptable position to take. In that case we should make sure that the message clearly conveys that the trait impl should be the only single implementation of this function.

@llogiq
Copy link
Contributor

llogiq commented Aug 25, 2015

LGTM. We could opt to add PartialOrd later, but I don't think this should keep us from merging.

r+, but I'll let @Manishearth merge.

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