Skip to content

Conversation

@kyoto7250
Copy link
Contributor

close #8851

This PR adds new lint about considering replacing .get(0) with .first().

Thank you in advance.

changelog: adds new lint [get_first] to consider replacing .get(0) with .first()

@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 May 24, 2022
@kyoto7250 kyoto7250 marked this pull request as ready for review May 24, 2022 14:00
Copy link
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

This is already looking quite good. I only have one small suggestion.

impl<'tcx> LateLintPass<'tcx> for GetFirst {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
if_chain! {
if let hir::ExprKind::MethodCall(_, expr_args, _) = &expr.kind;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using

Suggested change
if let hir::ExprKind::MethodCall(_, expr_args, _) = &expr.kind;
if let hir::ExprKind::MethodCall(_, [struct_calling_on, method_arg], _) = &expr.kind;

would make the expr_args.len() == 2 check and the expr_args.get(_) checks obsolete.

Copy link
Contributor Author

@kyoto7250 kyoto7250 May 25, 2022

Choose a reason for hiding this comment

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

Fixed in this commit.

Thanks!

@bors
Copy link
Contributor

bors commented May 24, 2022

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

@kyoto7250
Copy link
Contributor Author

kyoto7250 commented May 25, 2022

@llogiq

I rebased to the latest master and committed your suggestion :)

@llogiq
Copy link
Contributor

llogiq commented May 25, 2022

Thank you!

@bors r+

@bors
Copy link
Contributor

bors commented May 25, 2022

📌 Commit d0f93c1 has been approved by llogiq

@bors
Copy link
Contributor

bors commented May 25, 2022

⌛ Testing commit d0f93c1 with merge 3cc50a4...

@bors
Copy link
Contributor

bors commented May 25, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 3cc50a4 to master...

@bors bors merged commit 3cc50a4 into rust-lang:master May 25, 2022
@CBSpeir CBSpeir mentioned this pull request May 2, 2024
bors added a commit that referenced this pull request May 2, 2024
Remove `dead_code` paths

The following paths are `dead_code` and can be removed:

### `clippy_utils::paths::VEC_RESIZE`
* Introduced when `vec_resize_to_zero` lint added in PR #5637
* No longer used after commit 8acc4d2
### `clippy_utils::paths::SLICE_GET`
* Introduced when `get_first` lint added in PR #8882
* No longer used after commit a8d80d5
### `clippy_utils::paths::STR_BYTES`
* Introduced when `bytes_count_to_len` lint added in PR #8711
* No longer used after commit ba6a459

When the lints were moved into the `Methods` lint pass, they switched from using paths to diagnostic items.  However, the paths were never removed.  This occurred in PR #8957.

This relates to issue #5393

changelog: none
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.

New lint: use slice.first() instead of slice.get(0)

4 participants