Skip to content

WIP: Lots of fixes from clippy #46960

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

Closed
wants to merge 1 commit into from

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Dec 23, 2017

Will continue to add more changes to this until it's merged. This was the result of running cargo clippy on libcore and liballoc, although I didn't get close to fixing everything. I'll continue to add changes as I look through what clippy says, but I'm going to put this up now so that people can review the existing changes.

I'd be willing to split this into multiple commits if preferred.

@rust-highfive
Copy link
Contributor

r? @alexcrichton

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

@leonardo-m
Copy link

I think that changes to the Vec and similar parts should be done carefully, with benchmarks too.

@killercup
Copy link
Member

This is awesome!

The if … else { if … else … } to if … else if … else changes make this diff larger than it needs to be. Read it without whitespace changes

@@ -27,7 +27,7 @@
//! We can explicitly specify `hello_world`'s lifetime as well:
//!
//! ```
//! let hello_world: &'static str = "Hello, world!";
Copy link
Contributor

Choose a reason for hiding this comment

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

this is in documentation showing how to explicitly specify a lifetime, so it shouldn't be removed

Copy link
Member

Choose a reason for hiding this comment

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

Yes, can this be reverted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 27, 2017
@@ -105,6 +105,7 @@ def error(f, e, z):

//! Tables of approximations of powers of ten.
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
Copy link
Member

Choose a reason for hiding this comment

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

Can annotations like this be omitted? We don't run clippy in the main repository regularly so I'd prefer to not land annotations like this which are basically unused by all our infrastructure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

@@ -0,0 +1 @@
doc-valid-idents = ["TimSort"]
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, can this be omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@@ -27,7 +27,7 @@
//! We can explicitly specify `hello_world`'s lifetime as well:
//!
//! ```
//! let hello_world: &'static str = "Hello, world!";
Copy link
Member

Choose a reason for hiding this comment

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

Yes, can this be reverted?

@@ -2337,22 +2338,20 @@ impl<T> Iterator for IntoIter<T> {
unsafe {
if self.ptr as *const _ == self.end {
None
} else if mem::size_of::<T>() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be left as it was, it's a bit clearer in terms of control flow previously

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 can revert it but I'm a little confused how else { if is more clear than else if; it just adds unnecessary indentation IMHO.

if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
} else if mem::size_of::<T>() == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, can this be left as it was?

@@ -2485,7 +2482,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
impl<'a, T> Drop for Drain<'a, T> {
fn drop(&mut self) {
// exhaust self first
while let Some(_) = self.next() {}
for _ in self.by_ref() {}
Copy link
Member

Choose a reason for hiding this comment

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

Can this be left as it was? This is a pretty unsafe implementation so having it be as clear/simple as possible (less layers of abstraction) makes it easier to audit and see what's going on.

} else {
if (tail - head) >= cmp::min((cap - tail), head) {
Copy link
Member

Choose a reason for hiding this comment

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

Similar to aove, can this be left as it was?

// NOTE: The following code was generated by "src/etc/char_private.py",
// do not edit directly!
//! NOTE: The following code was generated by `src/etc/char_private.py`;
//! do not edit directly!
Copy link
Member

Choose a reason for hiding this comment

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

This I believe wasn't intended to be a doc comment, can the ! be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay!

@clarfonthey
Copy link
Contributor Author

I think it'll be best to just resubmit this PR as a series of smaller PRs for clarity. Closing this one.

@clarfonthey clarfonthey closed this Jan 3, 2018
@clarfonthey clarfonthey deleted the fixes_from_clippy branch January 29, 2022 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants