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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ __pycache__/
/obj/
/rt/
/rustllvm/
/src/etc/UnicodeData.txt
/src/libstd_unicode/DerivedCoreProperties.txt
/src/libstd_unicode/DerivedNormalizationProps.txt
/src/libstd_unicode/PropList.txt
Expand Down
15 changes: 8 additions & 7 deletions src/etc/char_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def compress_normal(normal):
return compressed

def print_singletons(uppers, lowers, uppersname, lowersname):
print("const {}: &'static [(u8, u8)] = &[".format(uppersname))
print("const {}: &[(u8, u8)] = &[".format(uppersname))
for u, c in uppers:
print(" ({:#04x}, {}),".format(u, c))
print("];")
print("const {}: &'static [u8] = &[".format(lowersname))
print("const {}: &[u8] = &[".format(lowersname))
for i in range(0, len(lowers), 8):
print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8])))
print("];")

def print_normal(normal, normalname):
print("const {}: &'static [u8] = &[".format(normalname))
print("const {}: &[u8] = &[".format(normalname))
for v in normal:
print(" {}".format(" ".join("{:#04x},".format(i) for i in v)))
print("];")
Expand Down Expand Up @@ -187,8 +187,8 @@ def main():
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// 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!

fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8],
normal: &[u8]) -> bool {
Expand Down Expand Up @@ -226,12 +226,13 @@ def main():
current
}

#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
pub(crate) fn is_printable(x: char) -> bool {
let x = x as u32;
let lower = x as u16;
if x < 0x10000 {
if x < (1 << 16) {
check(lower, SINGLETONS0U, SINGLETONS0L, NORMAL0)
} else if x < 0x20000 {
} else if x < (2 << 16) {
check(lower, SINGLETONS1U, SINGLETONS1L, NORMAL1)
} else {\
""")
Expand Down
1 change: 1 addition & 0 deletions src/etc/dec2flt_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!

"""


Expand Down
10 changes: 5 additions & 5 deletions src/liballoc/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Layout {
// the allocator to yield an error anyway.)

let len_rounded_up = len.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1);
return len_rounded_up.wrapping_sub(len);
len_rounded_up.wrapping_sub(len)
}

/// Creates a layout describing the record for `n` instances of
Expand Down Expand Up @@ -800,9 +800,9 @@ pub unsafe trait Alloc {
// _l <= layout.size() [guaranteed by usable_size()]
// layout.size() <= new_layout.size() [required by this method]
if new_layout.size <= u {
return Ok(());
Ok(())
} else {
return Err(CannotReallocInPlace);
Err(CannotReallocInPlace)
}
}

Expand Down Expand Up @@ -858,9 +858,9 @@ pub unsafe trait Alloc {
// layout.size() <= _u [guaranteed by usable_size()]
// new_layout.size() <= layout.size() [required by this method]
if l <= new_layout.size {
return Ok(());
Ok(())
} else {
return Err(CannotReallocInPlace);
Err(CannotReallocInPlace)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ impl<T: ?Sized> Clone for Weak<T> {
}
}

return Weak { ptr: self.ptr };
Weak { ptr: self.ptr }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct Box<T: ?Sized>(Unique<T>);
/// compiler. Easier just to make this parallel type for now.
///
/// FIXME (pnkfelix): Currently the `box` protocol only supports
/// creating instances of sized types. This IntermediateBox is
/// creating instances of sized types. This `IntermediateBox` is
/// designed to be forward-compatible with a future protocol that
/// supports creating instances of unsized types; that is why the type
/// parameter has the `?Sized` generalization marker, and is also why
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/clippy.toml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/liballoc/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ impl<'a, T> IterMut<'a, T> {
}
}

/// An iterator produced by calling `drain_filter` on LinkedList.
/// An iterator produced by calling `drain_filter` on `LinkedList`.
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
pub struct DrainFilter<'a, T: 'a, F: 'a>
where F: FnMut(&mut T) -> bool,
Expand Down
20 changes: 11 additions & 9 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ use super::boxed::Box;

/// A low-level utility for more ergonomically allocating, reallocating, and deallocating
/// a buffer of memory on the heap without having to worry about all the corner cases
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
/// involved. This type is excellent for building your own data structures like `Vec` and
/// `VecDeque`.
///
/// In particular:
///
/// * Produces Unique::empty() on zero-sized types
/// * Produces Unique::empty() on zero-length allocations
/// * Produces `Unique::empty()` on zero-sized types
/// * Produces `Unique::empty()` on zero-length allocations
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics)
/// * Guards against 32-bit systems allocating more than isize::MAX bytes
/// * Guards against 32-bit systems allocating more than `isize::MAX` bytes
/// * Guards against overflowing your length
/// * Aborts on OOM
/// * Avoids freeing Unique::empty()
/// * Contains a ptr::Unique and thus endows the user with all related benefits
/// * Avoids freeing `Unique::empty()`
/// * Contains a `ptr::Unique` and thus endows the user with all related benefits
///
/// This type does not in anyway inspect the memory that it manages. When dropped it *will*
/// free its memory, but it *won't* try to Drop its contents. It is up to the user of RawVec
/// to handle the actual things *stored* inside of a RawVec.
/// free its memory, but it *won't* try to Drop its contents. It is up to the user of `RawVec`
/// to handle the actual things *stored* inside of a `RawVec`.
///
/// Note that a RawVec always forces its capacity to be usize::MAX for zero-sized types.
/// Note that a `RawVec` always forces its capacity to be `usize::MAX` for zero-sized types.
/// This enables you to use capacity growing logic catch the overflows in your length
/// that might occur with zero-sized types.
///
Expand Down
4 changes: 2 additions & 2 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

//! let hello_world: &str = "Hello, world!";
//! ```
//!
//! *[See also the `str` primitive type](../../std/primitive.str.html).*
Expand Down Expand Up @@ -1995,7 +1995,7 @@ impl str {
pub fn to_uppercase(&self) -> String {
let mut s = String::with_capacity(self.len());
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
return s;
s
}

/// Escapes each char in `s` with [`char::escape_debug`].
Expand Down
14 changes: 5 additions & 9 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl String {
return Cow::Borrowed("");
};

const REPLACEMENT: &'static str = "\u{FFFD}";
const REPLACEMENT: &str = "\u{FFFD}";

let mut res = String::with_capacity(v.len());
res.push_str(first_valid);
Expand Down Expand Up @@ -1707,6 +1707,7 @@ impl<'a, 'b> Pattern<'a> for &'b String {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(partialeq_ne_impl))]
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for String {
#[inline]
Expand All @@ -1721,6 +1722,7 @@ impl PartialEq for String {

macro_rules! impl_eq {
($lhs:ty, $rhs: ty) => {
#[cfg_attr(feature = "cargo-clippy", allow(partialeq_ne_impl))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> PartialEq<$rhs> for $lhs {
#[inline]
Expand All @@ -1729,6 +1731,7 @@ macro_rules! impl_eq {
fn ne(&self, other: &$rhs) -> bool { PartialEq::ne(&self[..], &other[..]) }
}

#[cfg_attr(feature = "cargo-clippy", allow(partialeq_ne_impl))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> PartialEq<$lhs> for $rhs {
#[inline]
Expand Down Expand Up @@ -1969,7 +1972,7 @@ impl ops::DerefMut for String {
/// [`String`]: struct.String.html
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
#[stable(feature = "str_parse_error", since = "1.5.0")]
#[derive(Copy)]
#[derive(Copy, Clone)]
pub enum ParseError {}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -1981,13 +1984,6 @@ impl FromStr for String {
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl Clone for ParseError {
fn clone(&self) -> ParseError {
match *self {}
}
}

#[stable(feature = "str_parse_error", since = "1.5.0")]
impl fmt::Debug for ParseError {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn test_is_char_boundary() {
}
}
}
const LOREM_PARAGRAPH: &'static str = "\
const LOREM_PARAGRAPH: &str = "\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \
eros. Suspendisse sit amet magna mollis, mollis nunc luctus, imperdiet mi. Integer fringilla non \
Expand Down
11 changes: 4 additions & 7 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,7 @@ macro_rules! __impl_slice_eq1 {
};
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(feature = "cargo-clippy", allow(partialeq_ne_impl))]
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
#[inline]
fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] }
Expand Down Expand Up @@ -2337,8 +2338,7 @@ impl<T> Iterator for IntoIter<T> {
unsafe {
if self.ptr as *const _ == self.end {
None
} else {
if mem::size_of::<T>() == 0 {
} 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.

// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
Expand All @@ -2355,7 +2355,6 @@ impl<T> Iterator for IntoIter<T> {
}
}
}
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
Expand All @@ -2379,8 +2378,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
unsafe {
if self.end == self.ptr {
None
} else {
if mem::size_of::<T>() == 0 {
} 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?

// See above for why 'ptr.offset' isn't used
self.end = arith_offset(self.end as *const i8, -1) as *mut T;

Expand All @@ -2395,7 +2393,6 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
}
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ExactSizeIterator for IntoIter<T> {
Expand Down Expand Up @@ -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.


if self.tail_len > 0 {
unsafe {
Expand Down
6 changes: 2 additions & 4 deletions src/liballoc/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ impl<T> VecDeque<T> {
}
}

return elem;
elem
}

/// Splits the collection into two at the given index.
Expand Down Expand Up @@ -2479,8 +2479,7 @@ impl<T> From<VecDeque<T>> for Vec<T> {
// Need to move the ring to the front of the buffer, as vec will expect this.
if other.is_contiguous() {
ptr::copy(buf.offset(tail as isize), buf, len);
} 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?

} else if (tail - head) >= cmp::min((cap - tail), head) {
// There is enough free space in the centre for the shortest block so we can
// do this in at most three copy moves.
if (cap - tail) > head {
Expand Down Expand Up @@ -2527,7 +2526,6 @@ impl<T> From<VecDeque<T>> for Vec<T> {
right_edge += right_offset + 1;

}
}

}
let out = Vec::from_raw_parts(buf, len, cap);
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ impl Iterator for EscapeDefault {
None
}
},
EscapeDefaultState::Done => return None,
EscapeDefaultState::Unicode(ref mut i) => return i.nth(n),
EscapeDefaultState::Done => None,
EscapeDefaultState::Unicode(ref mut i) => i.nth(n),
}
}

Expand Down
Loading