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

Look at adjusted types instead of fn signature types in `ptr_arg`

Open y21 opened this issue 1 year ago • 1 comments

This simplifies the implementation of the ptr_arg lint a bit and: Fixes #13308 Fixes #10612

Currently, the lint checks if e.g. a &String parameter is only used in contexts where a &str could work. Part of it worked by looking for path exprs to that parameter in function call position specifically, looking at the callee signature and checking if that parameter type without refs is String (or one of a bunch of other special cases).

This simplified version removes the special casing of function calls and looking at the parameter type and instead just looks at the adjusted type, regardless of the expression it's in. This naturally also covers what the previous version was doing (if the expression is in a function call argument position expecting a &str, then it will have that adjustment. If it requires a &String then it won't have that adjustment and we won't lint).

The linked issue was a FP that happened because the previous implementation simply didn't consider projection types in the signature type, but with this simplification we don't really need to consider that (because we aren't looking at function signatures at all anymore -- the &mut Self::Owned parameter type of clone_into is the already-instantiated and normalized type &mut String).

changelog: none

y21 avatar Aug 27 '24 18:08 y21

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 avatar Aug 27 '24 18:08 rustbot

:umbrella: The latest upstream changes (presumably #13347) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 05 '24 15:09 bors

Thanks! @bors r+

Centri3 avatar Sep 13 '24 16:09 Centri3

:pushpin: Commit 15495ebf42a2d9748ae25774a73f28c43e47fd0b has been approved by Centri3

It is now in the queue for this repository.

bors avatar Sep 13 '24 16:09 bors

:hourglass: Testing commit 15495ebf42a2d9748ae25774a73f28c43e47fd0b with merge 25367459176bf0fd385594611d5a7c76fbcfa883...

bors avatar Sep 13 '24 16:09 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: Centri3 Pushing 25367459176bf0fd385594611d5a7c76fbcfa883 to master...

bors avatar Sep 13 '24 16:09 bors