Skip to content

Improve only_used_in_recursion lint/testing #8782

Closed
@flip1995

Description

@flip1995

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.E-needs-testCall for participation: writing testsI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions