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

More Clippy fixes for alloc, core and std #64178

Merged
merged 5 commits into from
Oct 24, 2019
Merged

Conversation

mati865
Copy link
Contributor

@mati865 mati865 commented Sep 5, 2019

Continuation of #63805

@rust-highfive
Copy link
Collaborator

r? @TimNN

(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 Sep 5, 2019
src/libstd/thread/mod.rs Outdated Show resolved Hide resolved
src/libstd/thread/mod.rs Outdated Show resolved Hide resolved
@@ -2742,7 +2742,7 @@ pub trait Iterator {
None => return true,
};

while let Some(curr) = self.next() {
for curr in self {
Copy link
Member

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 &muts. (Though it should arguably be rewritten as a try_fold...)

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

I would revert.

Copy link
Contributor Author

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?

@Alexendoo
Copy link
Member

Alexendoo commented Sep 18, 2019

Ping from triage, any updates? @scottmcm

@Alexendoo
Copy link
Member

Ping from triage, any updates? @TimNN

@TimNN
Copy link
Contributor

TimNN commented Oct 5, 2019

Sorry, I don't have the time right now to review Rust PRs, so

r? @scottmcm

since they already commented on this PR.

@rust-highfive rust-highfive assigned scottmcm and unassigned TimNN Oct 5, 2019
@JohnCSimon
Copy link
Member

Ping from triage
@scottmcm can you please review this?
Thanks

src/liballoc/borrow.rs Outdated Show resolved Hide resolved
if self.iter.nth(to_skip-1).is_none() {
return None;
}
self.iter.nth(to_skip - 1).as_ref()?;
Copy link
Member

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).

Copy link
Contributor Author

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?

@@ -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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@mati865 mati865 Oct 19, 2019

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?

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a 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.

@@ -2742,7 +2742,7 @@ pub trait Iterator {
None => return true,
};

while let Some(curr) = self.next() {
for curr in self {
Copy link
Member

Choose a reason for hiding this comment

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

I would revert.

src/libstd/thread/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@scottmcm scottmcm left a 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

src/libstd/thread/mod.rs Outdated Show resolved Hide resolved
src/libcore/option.rs Outdated Show resolved Hide resolved
@scottmcm scottmcm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 21, 2019
@mati865
Copy link
Contributor Author

mati865 commented Oct 21, 2019

Updated the code and the list of (my) open questions: #64178 (comment)

@rustbot modify labels: -S-waiting-on-author +S-waiting-on-review

@bors
Copy link
Contributor

bors commented Oct 22, 2019

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 22, 2019
@mati865 mati865 requested a review from scottmcm October 23, 2019 17:43
@scottmcm
Copy link
Member

Thanks, @mati865!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 23, 2019

📌 Commit bedbf3b has been approved by scottmcm

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 23, 2019
More Clippy fixes for alloc, core and std

Continuation of rust-lang#63805
bors added a commit that referenced this pull request Oct 24, 2019
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
@bors bors merged commit bedbf3b into rust-lang:master Oct 24, 2019
@mati865 mati865 deleted the clippy branch October 24, 2019 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.