-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
More Clippy fixes for alloc, core and std #64178
Conversation
r? @TimNN (rust_highfive has picked a reviewer for you, use r? to override) |
src/libcore/iter/traits/iterator.rs
Outdated
@@ -2742,7 +2742,7 @@ pub trait Iterator { | |||
None => return true, | |||
}; | |||
|
|||
while let Some(curr) = self.next() { | |||
for curr in self { |
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.
For comparison to the previous comment, this one seems fine, since it can move self
and doesn't add extra &mut
s. (Though it should arguably be rewritten as a try_fold
...)
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.
Thank you for explanation.
I cannot figure out how to change it to try_fold
so should I keep it or revert?
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.
I would revert.
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.
IIRC generated assembly was exactly the same but I'll drop it anyway.
Should I add FIXME about rewriting it with try_fold
?
|
Ping from triage, any updates? @TimNN |
Sorry, I don't have the time right now to review Rust PRs, so r? @scottmcm since they already commented on this PR. |
Ping from triage |
src/libcore/iter/adapters/mod.rs
Outdated
if self.iter.nth(to_skip-1).is_none() { | ||
return None; | ||
} | ||
self.iter.nth(to_skip - 1).as_ref()?; |
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.
I think this should not be done in this PR. Using ?
may have performance implications compared to the old code (as well as creating the reference -- which seems odd).
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.
I honestly have no idea about this as_ref()
, possibly it was added by IDE when I was applying lints.
?
has been used 14 times in this whole file although it performs a bit worse: https://godbolt.org/z/nHS4fh
I'll drop it but what about other 14 uses in this file, should they be left as is or replaced?
src/libcore/iter/traits/iterator.rs
Outdated
@@ -1684,6 +1684,7 @@ pub trait Iterator { | |||
/// assert_eq!(it.len(), 2); | |||
/// assert_eq!(it.next(), Some(&40)); | |||
/// ``` | |||
#[allow(clippy::while_let_on_iterator)] // uses mutable borrow resulting in worse assembly |
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.
I don't think we should add this to libstd, at least for now; I'm not sure libs team wants these scattered around.
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.
Sure I'll remove all Clippy annotations.
One day if Clippy is expected to be over Rust codebase this will be probably unavoidable though. Probably topic for a meeting.
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.
Also dropped mati865@694e625
Should I bring annotations topic to the libs teams somehow?
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.
A lot of these are fine but left a few comments.
src/libcore/iter/traits/iterator.rs
Outdated
@@ -2742,7 +2742,7 @@ pub trait Iterator { | |||
None => return true, | |||
}; | |||
|
|||
while let Some(curr) = self.next() { | |||
for curr in self { |
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.
I would revert.
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.
This looks pretty good, I have just two requests before r=me
Updated the code and the list of (my) open questions: #64178 (comment) @rustbot modify labels: -S-waiting-on-author +S-waiting-on-review |
☔ The latest upstream changes (presumably #65503) made this pull request unmergeable. Please resolve the merge conflicts. |
📌 Commit bedbf3b has been approved by |
More Clippy fixes for alloc, core and std Continuation of rust-lang#63805
Rollup of 12 pull requests Successful merges: - #64178 (More Clippy fixes for alloc, core and std) - #65144 (Add Cow::is_borrowed and Cow::is_owned) - #65193 (Lockless LintStore) - #65479 (Add the `matches!( $expr, $pat ) -> bool` macro) - #65518 (Avoid ICE when checking `Destination` of `break` inside a closure) - #65583 (rustc_metadata: use a table for super_predicates, fn_sig, impl_trait_ref.) - #65641 (Derive `Rustc{En,De}codable` for `TokenStream`.) - #65648 (Eliminate `intersect_opt`.) - #65657 (Remove `InternedString`) - #65691 (Update E0659 error code long explanation to 2018 edition) - #65696 (Fix an issue with const inference variables sticking around under Chalk + NLL) - #65704 (relax ExactSizeIterator bound on write_bytes) Failed merges: r? @ghost
Continuation of #63805