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

Lint also in trait def for wrong_self_convention #6316

Merged
merged 5 commits into from
Dec 19, 2020

Conversation

ThibsG
Copy link
Contributor

@ThibsG ThibsG commented Nov 10, 2020

Extends wrong_self_convention to lint also in trait definition.

By the way, I think the wrong_pub_self_convention example is misleading.
On playground, it fires wrong_self_convention, so the example (or the lint maybe?) needs to be reworked.
The difference with wrong_self_convention example is mainly the pub keyword on the method as_str, but the lint doesn't use the function visibility as condition to choose which lint to fire (in fact it uses the visibility of the impl item).

fixes: #6307

changelog: Lint wrong_self_convention lint in trait def also

@rust-highfive
Copy link

r? @ebroto

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 10, 2020
@ThibsG ThibsG force-pushed the WrongSelfConventionTraitDef branch 2 times, most recently from dc882a8 to e408a0c Compare November 10, 2020 11:28
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

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

I'm hesitating about this... do you think we should only lint if Sized is a supertrait of the given trait? Otherwise it would not make sense to refer to self in the error message; OTOH the conventions probably still hold and we should not use those names if we are not following them...


BTW sorry for the long delay in reviewing, I had almost no free time lately

tests/ui/use_self.rs Outdated Show resolved Hide resolved
tests/ui/wrong_self_convention.rs Show resolved Hide resolved
@ebroto ebroto added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Nov 23, 2020
@ebroto
Copy link
Member

ebroto commented Nov 23, 2020

By the way, I think the wrong_pub_self_convention example is misleading.
On playground, it fires wrong_self_convention, so the example (or the lint maybe?) needs to be reworked.
The difference with wrong_self_convention example is mainly the pub keyword on the method as_str, but the lint doesn't use the >function visibility as condition to choose which lint to fire (in fact it uses the visibility of the impl item).

Would you mind opening an issue about it? It would probably make sense to also look into the history of the lints, what were the reasons to split them (if that was the case)? It seems there are no tests for the pub variant, it would make sense to mention that in the issue.

Thanks!

@ebroto
Copy link
Member

ebroto commented Dec 7, 2020

Hey @ThibsG, something I can help with?

@ThibsG
Copy link
Contributor Author

ThibsG commented Dec 7, 2020

I am short on time recently, but I want to find some time to finish this soonish.
Btw it doesn't trigger when methods are only declared so more fun is waiting for me 😉

@ebroto
Copy link
Member

ebroto commented Dec 7, 2020

I am short on time recently, but I want to find some time to finish this soonish.

No problem!

Btw it doesn't trigger when methods are only declared so more fun is waiting for me wink

😆

@ebroto
Copy link
Member

ebroto commented Dec 8, 2020

BTW I checked and it seems to properly lint in required methods. Maybe you changed one of the negative tests? I tried changing the from_i32 one to:

fn from_i32(self);

@ThibsG ThibsG force-pushed the WrongSelfConventionTraitDef branch from e1077ae to c456b9e Compare December 10, 2020 16:10
@ThibsG
Copy link
Contributor Author

ThibsG commented Dec 10, 2020

You're right, the problem was between the chair and the desk, now it's all good by running the proper test 😅

@ThibsG ThibsG force-pushed the WrongSelfConventionTraitDef branch from c456b9e to 90a16e4 Compare December 10, 2020 16:54
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

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

LGTM mostly, but I'm hesitant about assuming that not linting in traits was an oversight.

This lint is one of the oldest ones, and I could not find the original issue or PR that added it to double check if there was a reason to avoid linting in trait defs.

@llogiq I know it's been a while 😄 but do you remember if this was intentional?

@ebroto ebroto removed the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Dec 12, 2020
@ebroto
Copy link
Member

ebroto commented Dec 19, 2020

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Dec 19, 2020

📌 Commit 90a16e4 has been approved by ebroto

@bors
Copy link
Contributor

bors commented Dec 19, 2020

⌛ Testing commit 90a16e4 with merge 9f9e9f7...

@bors
Copy link
Contributor

bors commented Dec 19, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: ebroto
Pushing 9f9e9f7 to master...

@bors bors merged commit 9f9e9f7 into rust-lang:master Dec 19, 2020
@ThibsG ThibsG deleted the WrongSelfConventionTraitDef branch December 20, 2020 17:08
@g2p
Copy link

g2p commented Dec 22, 2020

Hey @ThibsG !
It seems that when refactoring wrong_self_convention, you dropped a refinement that allowed passing Copy types by value; see #273 .
Could you restore this?

@ThibsG
Copy link
Contributor Author

ThibsG commented Dec 22, 2020

Oh you right, thanks @g2p for noting this.
I wasn't aware of this Copy exception.
I will fix this in coming days 😉

@ThibsG
Copy link
Contributor Author

ThibsG commented Dec 30, 2020

I double checked the changes made here and this PR doesn't modify the original behavior of the lint.
Particularly, when using #[derive(Copy)], the lint keeps quiet, as tested here.
Maybe the problem is coming from a particular situation I didn't see, so do not hesitate to reach me out if you have a precise case which was working earlier.

Not really interesting for your mentioned PR, but I agree one test could be added on the trait side, with a trait definition like trait C: Copy.
In this case the lint triggers both on from_i32(self) which is expected (same behavior with the derive macro test) and on into_i32(self) which is unexpected (not triggering with the derive macro test).
EDIT: this wasn't exactly the same test, one is with self, the other one with &self, so it's all good, I will just add this test in a future PR.

bors added a commit that referenced this pull request Jan 2, 2021
Ensure `Copy` exception in trait definition for `wrong_self_conventio…

Add a test case to ensure `Copy` exception is preserved also in trait definition, when passing `self` by value.

Follow up of #6316

changelog: none
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.

The wrong_self_convention lint should be applied to traits too
5 participants