-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
r? @xFrednet (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this 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 🤔
@bors delegate+ |
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. |
Please backport this. Paper cuts in clippy lints lead to them being disabled in my codebases. I almost never revisit an |
I agree and this shouldn't be a problem, that's why I asked. @rustbot label +beta-nominated |
/// ### 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. | ||
/// |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
LGTM, thank you for the update :) @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This lint does not exist in |
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 appropriateApplicability
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 aself
argument.IntoIterator::Iter
associated type doesn't exist. This should've just beenItem
.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 forinto_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)