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

Open
wants to merge 9 commits into
base: master
from

Conversation

@mati865
Copy link
Contributor

commented Sep 5, 2019

Continuation of #63805

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Sep 5, 2019

r? @TimNN

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


// Return notification or do nothing on spurious notifications
if let Ok(_) = thread.inner.state.compare_exchange(NOTIFIED, EMPTY, SeqCst, SeqCst) {
return;

This comment has been minimized.

Copy link
@mati865

mati865 Sep 5, 2019

Author Contributor

I'm not entirely sure about this one. Alternatively I can just make Clippy ignore it.

src/libstd/thread/mod.rs Outdated Show resolved Hide resolved
@@ -1690,7 +1690,7 @@ pub trait Iterator {
Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Ok=B>
{
let mut accum = init;
while let Some(x) = self.next() {
for x in self {

This comment has been minimized.

Copy link
@scottmcm

scottmcm Sep 9, 2019

Member

I think this one is a bad idea -- it'll use the &mut impl Iterator version of iterator because it will try to move self. And that one is typically less efficient.

(This seems like one of those lints that makes more sense outside the standard library than inside super-core things like try_fold.)

This comment has been minimized.

Copy link
@mati865

mati865 Sep 9, 2019

Author Contributor

You are right, after inspecting the assembly it generated additional store instruction.
Disabled lint for this function:

#[allow(clippy::while_let_on_iterator)] // uses mutable borrow resulting in worse assembly
@@ -2742,7 +2742,7 @@ pub trait Iterator {
None => return true,
};

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

This comment has been minimized.

Copy link
@scottmcm

scottmcm Sep 9, 2019

Member

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

This comment has been minimized.

Copy link
@mati865

mati865 Sep 9, 2019

Author Contributor

Thank you for explanation.
I cannot figure out how to change it to try_fold so should I keep it or revert?

@@ -46,7 +46,8 @@ impl Handle {
pub fn into_raw(self) -> c::HANDLE {
let ret = self.raw();
mem::forget(self);
return ret;

ret

This comment has been minimized.

Copy link
@scottmcm

scottmcm Sep 9, 2019

Member

nit: the extra newlines in here are surprising to me. (They're more reasonable after close braces, but in a three-line function the blank line doesn't seem to be adding anything.)

This comment has been minimized.

Copy link
@mati865

mati865 Sep 9, 2019

Author Contributor

I tried to keep consistent but yeah it looks weird.
Should I revert it everywhere?

mati865 and others added 5 commits Sep 5, 2019

@mati865 mati865 force-pushed the mati865:clippy branch from 4d4d5d5 to 4e2aa9b Sep 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.