rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

WIP: New lint [`manual_position`]

Open GabrielBFern opened this issue 1 year ago • 1 comments

Add a new lint to detect manual implementation of position() using enumerate().find(_)

changelog: Add new [manual_position] lint

fixes #2282

I need help handling this case when I need to change the deref on the body of the closure.

    let v = [1, 2, 3, 5, 6];
    let _ = v.iter().enumerate().find(|(_, ch)|**ch == 3).unwrap().0;
    // Right now, the lint is suggesting this (which does not compile):
    let _ = v.iter().position(|ch|**ch == 3).unwrap();
    // but i think i need to make like this:
    let _ = v.iter().position(|ch|*ch == 3).unwrap();
    // or this:
    let _ = v.iter().position(|&ch|ch == 3).unwrap();

GabrielBFern avatar Feb 27 '24 01:02 GabrielBFern

r? @llogiq

rustbot has assigned @llogiq. 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 avatar Feb 27 '24 01:02 rustbot

I found this example. I think I need something similar, but I don't know how to create an expr from the closure suggestion I made to pass it to the deref_closure_args function. Or if I need to pass the original expr first to deref_closure_args, in this case, I cannot separate the arguments and the body of the closure.

GabrielBFern avatar Feb 28 '24 01:02 GabrielBFern

First, check whether the closure input pattern already does a deref (|&a| ..). If so, we just remove the deref. Otherwise, we can either avoid linting, lint without suggestion or walk through the closure body adding derefs to any ExprPath matching the input.

llogiq avatar Mar 15 '24 06:03 llogiq

Now here comes the triaging part, lol...

Hey @GabrielBFern, this is a ping from triage. There hasn't been any activity for some time, you're always welcome to ask questions (there's a zulip stream if you're interested). It's also fine if you don't have the time right now. We just want to check in and make sure that you're not stuck.

@rustbot author

J-ZhengLi avatar May 16 '24 16:05 J-ZhengLi

Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this!

Interested parties are welcome to pick this implementation up as well :)

@rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review

xFrednet avatar Jun 20 '24 20:06 xFrednet