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

Refactor lints in methods module #6896

Merged
merged 19 commits into from
Mar 22, 2021

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Mar 13, 2021

This PR refactors methods lints other than the lints I refactored in #6826 and moves some functions to methods/utils.rs.
Basically, I follow the instruction described in #6680.

For ease of review, I refactored step by step, keeping each commit small.

closes #6886
cc: @phansch, @flip1995, @Y-Nak

changelog: Move lints in methods module to their own modules and some function to methods/utils.rs.

@rust-highfive
Copy link

r? @llogiq

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 13, 2021
@TaKO8Ki TaKO8Ki changed the title [WIP] Refactor lints functions in methods module [WIP] Refactor lints in methods module Mar 13, 2021
@TaKO8Ki TaKO8Ki marked this pull request as draft March 13, 2021 09:31
@flip1995
Copy link
Member

r? @phansch since you reviewed the last PR and know the context.

@bors
Copy link
Contributor

bors commented Mar 15, 2021

☔ The latest upstream changes (presumably #6907) made this pull request unmergeable. Please resolve the merge conflicts.

@TaKO8Ki TaKO8Ki force-pushed the refactor-lints-in-methods-module branch from 3c8152d to 08cc1f7 Compare March 17, 2021 02:13
@TaKO8Ki TaKO8Ki changed the title [WIP] Refactor lints in methods module Refactor lints in methods module Mar 17, 2021
@TaKO8Ki TaKO8Ki marked this pull request as ready for review March 17, 2021 05:55
@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented Mar 17, 2021

@phansch, @flip1995, @Y-Nak
I'm ready for your review!

clippy_lints/src/methods/get_unwrap.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/into_iter_on_ref.rs Outdated Show resolved Hide resolved
use rustc_span::sym;

/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints.
pub(super) fn check(
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if chars_last_cmp::check and chars_next_cmp::check should be merged into this because they are almost the same and depend on each other. I think separating them in this way decreases readability and understandability. This also applies to chars_cmp_with_unwrap.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. I'm going to merge chars_last_cmp and chars_next_cmp and merge chars_next_cmp_with_unwrap and chars_last_cmp_with_unwrap.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to do it in a new PR.

@bors
Copy link
Contributor

bors commented Mar 17, 2021

☔ The latest upstream changes (presumably #6918) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

Sorry for the merge conflicts. Resolving those should be quite easy though, since #6918 only changed some imports.

@TaKO8Ki TaKO8Ki force-pushed the refactor-lints-in-methods-module branch from c3d0476 to b949d84 Compare March 17, 2021 15:28
@TaKO8Ki TaKO8Ki force-pushed the refactor-lints-in-methods-module branch from b949d84 to 602bcf3 Compare March 17, 2021 15:59
@phansch
Copy link
Member

phansch commented Mar 22, 2021

@bors r+

Thanks for your patience!

@bors
Copy link
Contributor

bors commented Mar 22, 2021

📌 Commit b6a2757 has been approved by phansch

@bors
Copy link
Contributor

bors commented Mar 22, 2021

⌛ Testing commit b6a2757 with merge 029777f...

@bors
Copy link
Contributor

bors commented Mar 22, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: phansch
Pushing 029777f to master...

@bors bors merged commit 029777f into rust-lang:master Mar 22, 2021
@TaKO8Ki TaKO8Ki deleted the refactor-lints-in-methods-module branch March 23, 2021 01:45
bors added a commit that referenced this pull request Mar 31, 2021
Destructure args in `methods`

changelog: none

This changes the main pattern in `methods` to match and destructure the method call args at the same time as the method name, and pass individual arg `Expr`s to the lint impls.

```rust
// before
["expect", ..] => expect::check(cx, expr, arg_lists[0]);
// after
("expect", [arg]) => expect::check(cx, expr, recv, arg);
```

This makes the code safer since there is no risk of out of bounds `args[n]` everywhere. There will be no more collecting `method_names`, `arg_lists`, `method_spans` as a separate step - everything comes out of the `match`es. Chained methods are parsed in a nested `match`. This makes the code more verbose in some ways, but IMO it is much easier to follow.

~Definitely should wait for #6896. Just putting out the idea.~
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.

[Tracking Issue] Refactor lints in methods module
7 participants