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

New lint [iter_skip_zero] #11046

Merged
merged 1 commit into from
Jul 19, 2023
Merged

New lint [iter_skip_zero] #11046

merged 1 commit into from
Jul 19, 2023

Conversation

Centri3
Copy link
Member

@Centri3 Centri3 commented Jun 29, 2023

Idea came from my contribution to unnecessary_cast recently. Sorry about that 😅

Could be an issue if somebody manually implements skip, but I don't think anybody will (and this would be an issue with other lints too, afaik)

changelog: New lint [iter_skip_zero]

@rustbot
Copy link
Collaborator

rustbot commented Jun 29, 2023

r? @xFrednet

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 29, 2023
@xFrednet
Copy link
Member

r? @blyxyas

(xFrednet has picked a reviewer for you, use r? to override)

@rust-lang rust-lang deleted a comment from rustbot Jun 29, 2023
Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

Very interesting concept for a lint. It has some things I'd like to talk about, but very good overall ❤️

@@ -257,7 +257,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
// Will this work for more complex types? Probably not!
if !snippet
.split("->")
.skip(0)
.skip(1)
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure this change doesn't break anything? Won't this cause wrong suggestions? Probably the safest bet is to create a FIXME pointing to this commit and a brief explaination.


Just tested it, indeed .skip(0) to .skip(1) produce different results. Playground link

Copy link
Member Author

@Centri3 Centri3 Jun 29, 2023

Choose a reason for hiding this comment

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

Yep, .skip(0) does nothing. It's meant to skip anything before -> as that's known to not be the return type (and results in FPs if it contains ::std::primitive::u32 or the like). I wrote that code before so :D

/// ```rust
/// let v = vec![1, 2, 3];
/// let x = v.iter().skip(0).collect::<Vec<_>>();
/// let y = v.iter().collect::<Vec<_>>();
Copy link
Member

Choose a reason for hiding this comment

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

Could you re-write this example section so it follows by the general docs. guidelines? (using "Could be written as" and such)

Copy link
Member Author

Choose a reason for hiding this comment

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

There's a good few others like that (only example, mostly self-explanatory lints)

clippy_lints/src/methods/iter_skip_zero.rs Outdated Show resolved Hide resolved
clippy_lints/src/methods/iter_skip_zero.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jul 1, 2023

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

@Centri3 Centri3 force-pushed the iter_skip_zero branch 2 times, most recently from 877daff to 2604a06 Compare July 2, 2023 16:46
@bors
Copy link
Contributor

bors commented Jul 5, 2023

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

@Centri3 Centri3 force-pushed the iter_skip_zero branch 2 times, most recently from 9ce8868 to a0b76d4 Compare July 19, 2023 05:52
@bors
Copy link
Contributor

bors commented Jul 19, 2023

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

Copy link
Member

@blyxyas blyxyas left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks ❤️ !

@xFrednet
Copy link
Member

xFrednet commented Jul 19, 2023

You should have bors permissions, once the team PR is merged. For now, I can delegate these PRs to you two :)

@bors delegate @Centri3
@bors delegate @blyxyas

@xFrednet
Copy link
Member

Theoretically, if I get the comment right

@bors delegate=blyxyas
@bors delegate=Centri3

@bors
Copy link
Contributor

bors commented Jul 19, 2023

✌️ @blyxyas, you can now approve this pull request!

If @xFrednet told you to "r=me" after making some further change, please make that change, then do @bors r=@xFrednet

@bors
Copy link
Contributor

bors commented Jul 19, 2023

✌️ @Centri3, you can now approve this pull request!

If @xFrednet told you to "r=me" after making some further change, please make that change, then do @bors r=@xFrednet

@blyxyas
Copy link
Member

blyxyas commented Jul 19, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Jul 19, 2023

@blyxyas: 🔑 Insufficient privileges: Not in reviewers

@blyxyas
Copy link
Member

blyxyas commented Jul 19, 2023

Life is hard

@blyxyas
Copy link
Member

blyxyas commented Jul 19, 2023

@bors r=xFrednet

@bors
Copy link
Contributor

bors commented Jul 19, 2023

@blyxyas: 🔑 Insufficient privileges: Not in reviewers

@blyxyas
Copy link
Member

blyxyas commented Jul 19, 2023

Maybe the second delegation overwrote the first one? @Centri3 could you try?

@Centri3
Copy link
Member Author

Centri3 commented Jul 19, 2023

Maybe, @bors r=blyxyas

@bors
Copy link
Contributor

bors commented Jul 19, 2023

📌 Commit 4c79d8a has been approved by blyxyas

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 19, 2023

⌛ Testing commit 4c79d8a with merge 3dd6af9...

@bors
Copy link
Contributor

bors commented Jul 19, 2023

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

@bors bors merged commit 3dd6af9 into rust-lang:master Jul 19, 2023
@Centri3 Centri3 deleted the iter_skip_zero branch July 19, 2023 09:15
@xFrednet
Copy link
Member

WTF? So picky that boy

Hey @bors be nicer to our newest members. Honer their new power!!! ✨

@proski
Copy link

proski commented Oct 30, 2023

Just for the record, this lint breaks Alacritty. It has code that skips some non-zero amount of characters in one branch but doesn't skip anything in another. The result is stored in the same structure field of the type Skip<Chars>.

skip(0) is used to convert the type from Chars to Skip<Chars>. I wish I could use something else, but I don't see what would be a good replacement. There is no into() implementation either from the original iterator to Skip or from Skip to the original. advance_by is nightly-only, so it cannot be used yet.

https://github.com/alacritty/alacritty/blob/75eef3be9680dbe3300186b06e19eac7f9dfab4b/alacritty/src/string.rs#L32

@blyxyas
Copy link
Member

blyxyas commented Oct 31, 2023

This lint can be allowed by using an attribute like #<!>[allow(clippy::iter_skip_zero)] in the code, -- -A clippy::iter_skip_zero in the terminal or CI, or even by adding lints.clippy.iter_skip_zero = "allow" in your Cargo.toml.

I'm not seeing how this is an issue, or how a lint can break a project other than generating some new error messages in the CI.

@Centri3
Copy link
Member Author

Centri3 commented Nov 1, 2023

Probably the fix that breaks it? We should call expr_use_ctxt to handle this

@proski
Copy link

proski commented Nov 2, 2023

Thank you for the responses! I didn't mean to say that the issue cannot be ignored in the code. My point is that there are legitimate uses of skip(0). They can seem contrived, but there is a real life example.

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.

6 participants