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

Add check_self_items setting for needless_pass_by_ref_mut lint #12648

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Apr 8, 2024

Fixes #12589.
Fixes #9591.

This adds a check_self_items setting to allow the needless_pass_by_ref_mut lint to check for &mut self items.

changelog: Add check_self_items setting for needless_pass_by_ref_mut lint

@rustbot
Copy link
Collaborator

rustbot commented Apr 8, 2024

r? @Manishearth

rustbot has assigned @Manishearth.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 8, 2024
@GuillaumeGomez GuillaumeGomez force-pushed the needless_pass_by_ref_mut-check_self_items branch from b115ce2 to dcdd67d Compare April 8, 2024 13:45
@GuillaumeGomez
Copy link
Member Author

Assigning someone else as I think they're still busy at the moment.

r? @llogiq

@rustbot rustbot assigned llogiq and unassigned Manishearth Apr 8, 2024
@klensy
Copy link
Contributor

klensy commented Apr 10, 2024

Should fix #9591 too?

@GuillaumeGomez
Copy link
Member Author

Ah indeed.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

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

it's unclear to me that a config is actually the solution here. we should first try to better understand the problem space.

@llogiq
Copy link
Contributor

llogiq commented Apr 11, 2024

Since I have a full plate already and he seems to have the PR well in hand, back to

@bors r? @Manishearth

@rustbot rustbot assigned Manishearth and unassigned llogiq Apr 11, 2024
@klensy
Copy link
Contributor

klensy commented Apr 12, 2024

it's unclear to me that a config is actually the solution here. we should first try to better understand the problem space.

For start, you can read linked issues, #9591, #10900 (comment)

@Manishearth
Copy link
Member

Yes, I'm not convinced that that is a case not better served with targeted allows.

For it to be a config I'd need to see a strong reason why this needs to be a codebase-wide decision.

@klensy
Copy link
Contributor

klensy commented Apr 13, 2024

Yes, I'm not convinced that that is a case not better served with targeted allows.

Targeted allows - what you mean? If i currently want to lint &mut self - there is no way to do this. This lint more useful for analysis of code (and for analysis i want to see more suggestions, including &mut selfs), not for automatically fixing all suggested things. Besides, this lint is in nursery.

@Manishearth
Copy link
Member

Ok, but if this lint were to unconditionally lint &mut self, what is the reason for someone to wish to disable that aspect of the check across the codebase? I understand wanting to do it for a specific type where there are special semantic needs, but those cases are fixed with a very warranted allow.

Basically what is the benefit of a config over making this available all the time?

Sure, this lint is in nursery, but why do work we may decide to undo at some point? For the lint to get out of nursery these discussions need to happen at some point, and there's not a huge benefit of waiting on this one.

@GuillaumeGomez
Copy link
Member Author

Ok, but if this lint were to unconditionally lint &mut self, what is the reason for someone to wish to disable that aspect of the check across the codebase? I understand wanting to do it for a specific type where there are special semantic needs, but those cases are fixed with a very warranted allow.

It's the other way around: this lint never lints &mut self and this PR adds a config to allow &mut self to be linted.

@Manishearth
Copy link
Member

Manishearth commented Apr 13, 2024

Yes, I understand: why does this have to be a config and not unconditional behavior?

My comment was talking about that hypothetical and comparing it with this PR.

@GuillaumeGomez
Copy link
Member Author

Thanks for clarifying. I was able to find my original answer about it here. Basically, you might want to keep &mut self to ensure that even though self is not used mutably, you want to restrain its access. Maybe it's too far fetched though. I don't have a strong opinion about it nor do I have a use case where I actually need this use case.

@Manishearth
Copy link
Member

Yes, why is that use case not adequately satisfied by allow? What is the reason to want to disable that for the entire crate? That's when you have a config.

And I don't think it's concrete enough.

@GuillaumeGomez
Copy link
Member Author

In short, I was trying to limit the scope of the lint as much as possible. That's the only backing to it. Like I said, we could enable it by default and instead have this config to disable this behaviour.

@Manishearth
Copy link
Member

Yeah in general config options expand the scope of a lint and need to have a strong reason

@GuillaumeGomez
Copy link
Member Author

Just to confirm: following your logic, if the config would be to disable the check on self, wouldn't it be the opposite of an expansion of a lint scope? Or did I misunderstood what you meant?

@Manishearth
Copy link
Member

No. I'm saying having a config in the first place, regardless of what it does, expands the scope of a lint because it's effectively multiple lints now. We should avoid that unless both lints can be justified. I can't see a strong justification for the "no-lint-self" version of this lint.

@GuillaumeGomez
Copy link
Member Author

Makes sense. Gonna update this lint to check for self as well instead then.

@GuillaumeGomez
Copy link
Member Author

Closing in favor of #12693.

@GuillaumeGomez GuillaumeGomez deleted the needless_pass_by_ref_mut-check_self_items branch April 18, 2024 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

needless_pass_by_ref_mut: false negative, &mut self ignored self doesn't need to be mutable lint
5 participants