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

clippy::redundant_locals is not a correctness lint #13747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hrxi
Copy link
Contributor

@hrxi hrxi commented Nov 28, 2024

Even its documentation says so. According to the documentation, it might either be a "suspicious" or a "perf" lint.

changelog: [redundant_locals]: Reclassify as "suspicious" lint.

@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2024

r? @Centri3

rustbot has assigned @Centri3.
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 Nov 28, 2024
Copy link
Member

@Centri3 Centri3 left a comment

Choose a reason for hiding this comment

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

I don't particularly agree. Where does it say it in the documentation? For:

and are likely to be unintended

This kind of wording is normal for correctness lints, see for example
clippy::absurd_extreme_comparisons: "Expressions like max < x are probably mistakes.".
clippy::match_str_case_mismatch: "The arm is unreachable, which is likely a mistake".
This should have stronger wording tho. Mostly mentioning that it could be an error from refactoring.

they may affect rustc's stack allocation.

Is specifically related to cases like rust-lang/rust#112478 which isn't really relevant

In any case I'd say opening a thread on zulip is a good idea. Note this has no impact on performance so it'd only ever be suspicious.

@hrxi
Copy link
Contributor Author

hrxi commented Nov 28, 2024

Correctness to me sounds like there's likely a mistake somewhere, i.e. that the code doesn't do what it's supposed to do. In the code fragment where the lint triggered for me, there was no mistake, it was just an unnecessary line ­— but that's not what a correctness lint is for.

What incorrect code does this lint have in mind that might be detected using this lint?

@Centri3
Copy link
Member

Centri3 commented Nov 28, 2024

correctness is defined in the readme as "code that is outright wrong or useless". This code is outright wrong and useless, while yes what it's doing wrong is a very light bug in nature (which could in the end just be an unnecessary line), I'd say because this could easily be caused by a user-error in refactoring it might be indicative of issues elsewhere too, where that assignment was supposed to do something.

This fits both correctness and suspicious, it's just whether it should deny compilation or not. See also clippy::self_assignment for a similar correctness lint

@Centri3
Copy link
Member

Centri3 commented Dec 14, 2024

Even its documentation says so. According to the documentation, it might
either be a "suspicious" or a "perf" lint.
@hrxi hrxi force-pushed the pr_reclassify_redundant_locals branch from 10442f6 to 221dc38 Compare December 14, 2024 23:33
@hrxi
Copy link
Contributor Author

hrxi commented Dec 14, 2024

I don't feel strongly about whether it's a suspicious or perf lint, I just think that it shouldn't fail compilation outright.

Since you don't feel strongly about its classification as correctness or suspicious, let's just pick suspicious?

(I don't have a zulip account.)

Copy link
Member

@Centri3 Centri3 left a comment

Choose a reason for hiding this comment

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

From the zulip thread: Ok with and in favor of suspicious for now(?) 👍 Just one change I'd recommend: while talking about stack allocations, it could mention this rarely being intentional to shorten lifetimes.

@hrxi
Copy link
Contributor Author

hrxi commented Dec 24, 2024

Just one change I'd recommend: while talking about stack allocations, it could mention this rarely being intentional to shorten lifetimes.

I'm not sure which change you recommend me to make. I don't see anything about lifetimes in the description of the lint.

@Centri3
Copy link
Member

Centri3 commented Dec 24, 2024

It should mention this "redundant" redefinition as being intentional in these cases: https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Lint.20level.20for.20.60redundant_locals.60/near/489074952

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.

3 participants