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

[iter_without_into_iter]: fix papercuts in suggestion and restrict linting to exported types #11696

Merged
merged 3 commits into from
Oct 28, 2023

Conversation

y21
Copy link
Member

@y21 y21 commented Oct 22, 2023

See #11692 for more context.

tldr: the lint iter_without_into_iter has suggestions that don't compile, which imo isn't that problematic because it does have the appropriate Applicability that tells external tools that it shouldn't be auto-applied.
However there were some obvious "errors" in the suggestion that really should've been included in my initial PR adding the lint, which is fixed by this PR:

  • IntoIterator::into_iter needs a self argument.
  • IntoIterator::Iter associated type doesn't exist. This should've just been Item.

This still doesn't make it machine applicable, and the remaining things are imho quite non-trivial to implement, as I've explained in #11692 (comment).
I personally think it's fine to leave it there and let the user change the remaining errors when copy-pasting the suggestion (e.g. errors caused by lifetimes that were permitted in fn return-position but are not in associated types).
This is how many of our other lint suggestions already work.

Also, we now restrict linting to only exported types. This required moving basically all of the tests around since they were previously in the main function. Same for into_iter_without_iter. The git diff is a bit useless here...

changelog: [iter_without_into_iter]: fix papercuts in suggestion and restrict linting to exported types

(cc @lopopolo, figured I should mention you since you created the issue)

@rustbot
Copy link
Collaborator

rustbot commented Oct 22, 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 Oct 22, 2023
Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

LGTM, I have one small suggestion, and then you can r=me. Also thank you for the fix :D

Clippy's documentation says that this lint will be stabilized in rust 1.74. Do you think this is worth a beta backport? It's a pedantic lint, which doesn't make it super necessary, but the restriction to only exported items, might make a big difference, to the amount of lint triggers 🤔

clippy_lints/src/iter_without_into_iter.rs Show resolved Hide resolved
@xFrednet
Copy link
Member

@bors delegate+

@bors
Copy link
Contributor

bors commented Oct 25, 2023

✌️ @y21, 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

@y21
Copy link
Member Author

y21 commented Oct 25, 2023

Do you think this is worth a beta backport?

I think it's a good idea, even for a pedantic lint. It's not all that useful for private types imo and I think it could make a noticeable difference in how often the lint occurs. The errors in the suggestion were also pretty obvious so it would be nice if this fix gets into beta along with the PR that introduced this.
But if it's too much of a hassle or this is the only PR that is gonna be nominated for backporting, it might be unnecessary.

@lopopolo
Copy link

Please backport this. Paper cuts in clippy lints lead to them being disabled in my codebases. I almost never revisit an !#[allow(clippy::xxx)] once it gets added

@xFrednet
Copy link
Member

I agree and this shouldn't be a problem, that's why I asked. @flip1995 Usually does the beta back ports, a week or so before the release. To indicate that a fix should be back ported, we just need to add the beta-nominated label.

@rustbot label +beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 26, 2023
Comment on lines 69 to 74
/// ### Limitations
/// This lint is restricted to exported types only, because it is aimed at guiding towards an
/// idiomatic, _public_ API.
/// Adding an `iter` or `iter_mut` for private types when it is not needed or used doesn't improve code,
/// and in fact, is linted against by the `dead_code` lint.
///
Copy link
Member

Choose a reason for hiding this comment

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

The current version is fine. I would formulate it a bit differently, but this is mostly a question of taste. I leave the decision up to you, which one you like more, or if you want to combine the two versions :)

    /// ### Limitations
    /// This lint focusess on providing an idiomatic API. Therefore, it will only
    /// lint on types, which are accessible outside of the crate. For internal types
    /// these methods can be added on demand, if they are acually needed. Otherwise,
    /// it would trigger the [`dead_code`] lint for the unused method.
    ///
    /// [`dead_code`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#dead-code

Copy link
Member Author

Choose a reason for hiding this comment

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

Adjusted the documentation a bit with your suggestions in mind.

@xFrednet
Copy link
Member

LGTM, thank you for the update :)

@bors r+

@bors
Copy link
Contributor

bors commented Oct 28, 2023

📌 Commit 9a10d32 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Oct 28, 2023

⌛ Testing commit 9a10d32 with merge f8409ef...

@bors
Copy link
Contributor

bors commented Oct 28, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing f8409ef to master...

@bors bors merged commit f8409ef into rust-lang:master Oct 28, 2023
4 checks passed
@flip1995
Copy link
Member

flip1995 commented Nov 9, 2023

This lint does not exist in beta yet and this PR was already synced to rustc. So this PR will be included when this lint gets to beta and ultimately stable. => Nothing to do for me. My favorite kind of backports 🙃

@flip1995 flip1995 removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 9, 2023
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