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

Improve only_used_in_recursion lint/testing #8782

Closed
flip1995 opened this issue May 3, 2022 · 0 comments · Fixed by #8804
Closed

Improve only_used_in_recursion lint/testing #8782

flip1995 opened this issue May 3, 2022 · 0 comments · Fixed by #8804
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. E-needs-test Call for participation: writing tests I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@flip1995
Copy link
Member

flip1995 commented May 3, 2022

I tried to read the code of the lint for over an hour and couldn't really follow what it is doing. I was also able to remove large junks of code from the visitor and the tests kept passing. This signals to me that the logic the lint code is following isn't really tested.

The tests that are there could mostly also be linted with simpler linting code. Also there is a test, that with slight modifications produces a FP:

fn break_(a: usize, mut b: usize, mut c: usize) -> usize {
let c = loop {
b += 1;
c += 1;
if c == 10 {
break b;
}
};
if a == 0 { 1 } else { break_(a - 1, c, c) }
}

If you add a if c >= 10 { return 4; } at the top of the function, you still get the lint. But removing the b argument changes the semantics of the function (i.e. you won't be able to get the same behavior). Playground

I think we should just bail out if the parameter is used anywhere other than directly as its own function argument.

I also have the suspicion that this lint might be a significant perf regression for Clippy.

I think we should move this lint to nursery and not run it if the lint is allowed for now. I like this lint in general, but I think in the current state it is over engineered and not really maintainable.

Originally posted by @flip1995 in #8689 (comment)

@flip1995 flip1995 added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-needs-test Call for participation: writing tests I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 3, 2022
bors added a commit that referenced this issue May 3, 2022
Move only_used_in_recursion to nursery

r? `@llogiq`

I still think this is the right thing to do for this lint. See: #8782

I want to get this merged before the sync on Thursday, because I want to backport this and the last fix #8691 to beta.

changelog: Move [`only_used_in_recursion`] to nursery
@bors bors closed this as completed in 3a54117 Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages E-medium Call for participation: Medium difficulty level problem and requires some initial experience. E-needs-test Call for participation: writing tests I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant