Skip to content

Commit 51d91e0

Browse files
author
Clar Charr
committed
Lots of fixes from clippy
1 parent 5165ee9 commit 51d91e0

File tree

24 files changed

+141
-139
lines changed

24 files changed

+141
-139
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ __pycache__/
7474
/obj/
7575
/rt/
7676
/rustllvm/
77+
/src/etc/UnicodeData.txt
7778
/src/libstd_unicode/DerivedCoreProperties.txt
7879
/src/libstd_unicode/DerivedNormalizationProps.txt
7980
/src/libstd_unicode/PropList.txt

src/etc/char_private.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ def compress_normal(normal):
121121
return compressed
122122

123123
def print_singletons(uppers, lowers, uppersname, lowersname):
124-
print("const {}: &'static [(u8, u8)] = &[".format(uppersname))
124+
print("const {}: &[(u8, u8)] = &[".format(uppersname))
125125
for u, c in uppers:
126126
print(" ({:#04x}, {}),".format(u, c))
127127
print("];")
128-
print("const {}: &'static [u8] = &[".format(lowersname))
128+
print("const {}: &[u8] = &[".format(lowersname))
129129
for i in range(0, len(lowers), 8):
130130
print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8])))
131131
print("];")
132132

133133
def print_normal(normal, normalname):
134-
print("const {}: &'static [u8] = &[".format(normalname))
134+
print("const {}: &[u8] = &[".format(normalname))
135135
for v in normal:
136136
print(" {}".format(" ".join("{:#04x},".format(i) for i in v)))
137137
print("];")
@@ -187,8 +187,8 @@ def main():
187187
// option. This file may not be copied, modified, or distributed
188188
// except according to those terms.
189189
190-
// NOTE: The following code was generated by "src/etc/char_private.py",
191-
// do not edit directly!
190+
//! NOTE: The following code was generated by `src/etc/char_private.py`;
191+
//! do not edit directly!
192192
193193
fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8],
194194
normal: &[u8]) -> bool {
@@ -226,12 +226,13 @@ def main():
226226
current
227227
}
228228
229+
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
229230
pub(crate) fn is_printable(x: char) -> bool {
230231
let x = x as u32;
231232
let lower = x as u16;
232-
if x < 0x10000 {
233+
if x < (1 << 16) {
233234
check(lower, SINGLETONS0U, SINGLETONS0L, NORMAL0)
234-
} else if x < 0x20000 {
235+
} else if x < (2 << 16) {
235236
check(lower, SINGLETONS1U, SINGLETONS1L, NORMAL1)
236237
} else {\
237238
""")

src/etc/dec2flt_table.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def error(f, e, z):
105105
106106
//! Tables of approximations of powers of ten.
107107
//! DO NOT MODIFY: Generated by `src/etc/dec2flt_table.py`
108+
#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
108109
"""
109110

110111

src/liballoc/allocator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Layout {
204204
// the allocator to yield an error anyway.)
205205

206206
let len_rounded_up = len.wrapping_add(align).wrapping_sub(1) & !align.wrapping_sub(1);
207-
return len_rounded_up.wrapping_sub(len);
207+
len_rounded_up.wrapping_sub(len)
208208
}
209209

210210
/// Creates a layout describing the record for `n` instances of
@@ -800,9 +800,9 @@ pub unsafe trait Alloc {
800800
// _l <= layout.size() [guaranteed by usable_size()]
801801
// layout.size() <= new_layout.size() [required by this method]
802802
if new_layout.size <= u {
803-
return Ok(());
803+
Ok(())
804804
} else {
805-
return Err(CannotReallocInPlace);
805+
Err(CannotReallocInPlace)
806806
}
807807
}
808808

@@ -858,9 +858,9 @@ pub unsafe trait Alloc {
858858
// layout.size() <= _u [guaranteed by usable_size()]
859859
// new_layout.size() <= layout.size() [required by this method]
860860
if l <= new_layout.size {
861-
return Ok(());
861+
Ok(())
862862
} else {
863-
return Err(CannotReallocInPlace);
863+
Err(CannotReallocInPlace)
864864
}
865865
}
866866

src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ impl<T: ?Sized> Clone for Weak<T> {
10951095
}
10961096
}
10971097

1098-
return Weak { ptr: self.ptr };
1098+
Weak { ptr: self.ptr }
10991099
}
11001100
}
11011101

src/liballoc/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub struct Box<T: ?Sized>(Unique<T>);
120120
/// compiler. Easier just to make this parallel type for now.
121121
///
122122
/// FIXME (pnkfelix): Currently the `box` protocol only supports
123-
/// creating instances of sized types. This IntermediateBox is
123+
/// creating instances of sized types. This `IntermediateBox` is
124124
/// designed to be forward-compatible with a future protocol that
125125
/// supports creating instances of unsized types; that is why the type
126126
/// parameter has the `?Sized` generalization marker, and is also why

src/liballoc/clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["TimSort"]

src/liballoc/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ impl<'a, T> IterMut<'a, T> {
10321032
}
10331033
}
10341034

1035-
/// An iterator produced by calling `drain_filter` on LinkedList.
1035+
/// An iterator produced by calling `drain_filter` on `LinkedList`.
10361036
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
10371037
pub struct DrainFilter<'a, T: 'a, F: 'a>
10381038
where F: FnMut(&mut T) -> bool,

src/liballoc/raw_vec.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@ use super::boxed::Box;
1818

1919
/// A low-level utility for more ergonomically allocating, reallocating, and deallocating
2020
/// a buffer of memory on the heap without having to worry about all the corner cases
21-
/// involved. This type is excellent for building your own data structures like Vec and VecDeque.
21+
/// involved. This type is excellent for building your own data structures like `Vec` and
22+
/// `VecDeque`.
23+
///
2224
/// In particular:
2325
///
24-
/// * Produces Unique::empty() on zero-sized types
25-
/// * Produces Unique::empty() on zero-length allocations
26+
/// * Produces `Unique::empty()` on zero-sized types
27+
/// * Produces `Unique::empty()` on zero-length allocations
2628
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics)
27-
/// * Guards against 32-bit systems allocating more than isize::MAX bytes
29+
/// * Guards against 32-bit systems allocating more than `isize::MAX` bytes
2830
/// * Guards against overflowing your length
2931
/// * Aborts on OOM
30-
/// * Avoids freeing Unique::empty()
31-
/// * Contains a ptr::Unique and thus endows the user with all related benefits
32+
/// * Avoids freeing `Unique::empty()`
33+
/// * Contains a `ptr::Unique` and thus endows the user with all related benefits
3234
///
3335
/// This type does not in anyway inspect the memory that it manages. When dropped it *will*
34-
/// free its memory, but it *won't* try to Drop its contents. It is up to the user of RawVec
35-
/// to handle the actual things *stored* inside of a RawVec.
36+
/// free its memory, but it *won't* try to Drop its contents. It is up to the user of `RawVec`
37+
/// to handle the actual things *stored* inside of a `RawVec`.
3638
///
37-
/// Note that a RawVec always forces its capacity to be usize::MAX for zero-sized types.
39+
/// Note that a `RawVec` always forces its capacity to be `usize::MAX` for zero-sized types.
3840
/// This enables you to use capacity growing logic catch the overflows in your length
3941
/// that might occur with zero-sized types.
4042
///

src/liballoc/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! We can explicitly specify `hello_world`'s lifetime as well:
2828
//!
2929
//! ```
30-
//! let hello_world: &'static str = "Hello, world!";
30+
//! let hello_world: &str = "Hello, world!";
3131
//! ```
3232
//!
3333
//! *[See also the `str` primitive type](../../std/primitive.str.html).*
@@ -1995,7 +1995,7 @@ impl str {
19951995
pub fn to_uppercase(&self) -> String {
19961996
let mut s = String::with_capacity(self.len());
19971997
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
1998-
return s;
1998+
s
19991999
}
20002000

20012001
/// Escapes each char in `s` with [`char::escape_debug`].

src/liballoc/string.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl String {
575575
return Cow::Borrowed("");
576576
};
577577

578-
const REPLACEMENT: &'static str = "\u{FFFD}";
578+
const REPLACEMENT: &str = "\u{FFFD}";
579579

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

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

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

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

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

1984-
#[stable(feature = "str_parse_error", since = "1.5.0")]
1985-
impl Clone for ParseError {
1986-
fn clone(&self) -> ParseError {
1987-
match *self {}
1988-
}
1989-
}
1990-
19911987
#[stable(feature = "str_parse_error", since = "1.5.0")]
19921988
impl fmt::Debug for ParseError {
19931989
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {

src/liballoc/tests/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn test_is_char_boundary() {
416416
}
417417
}
418418
}
419-
const LOREM_PARAGRAPH: &'static str = "\
419+
const LOREM_PARAGRAPH: &str = "\
420420
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse quis lorem sit amet dolor \
421421
ultricies condimentum. Praesent iaculis purus elit, ac malesuada quam malesuada in. Duis sed orci \
422422
eros. Suspendisse sit amet magna mollis, mollis nunc luctus, imperdiet mi. Integer fringilla non \

src/liballoc/vec.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ macro_rules! __impl_slice_eq1 {
20612061
};
20622062
($Lhs: ty, $Rhs: ty, $Bound: ident) => {
20632063
#[stable(feature = "rust1", since = "1.0.0")]
2064+
#[cfg_attr(feature = "cargo-clippy", allow(partialeq_ne_impl))]
20642065
impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> {
20652066
#[inline]
20662067
fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] }
@@ -2337,22 +2338,20 @@ impl<T> Iterator for IntoIter<T> {
23372338
unsafe {
23382339
if self.ptr as *const _ == self.end {
23392340
None
2341+
} else if mem::size_of::<T>() == 0 {
2342+
// purposefully don't use 'ptr.offset' because for
2343+
// vectors with 0-size elements this would return the
2344+
// same pointer.
2345+
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;
2346+
2347+
// Use a non-null pointer value
2348+
// (self.ptr might be null because of wrapping)
2349+
Some(ptr::read(1 as *mut T))
23402350
} else {
2341-
if mem::size_of::<T>() == 0 {
2342-
// purposefully don't use 'ptr.offset' because for
2343-
// vectors with 0-size elements this would return the
2344-
// same pointer.
2345-
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;
2346-
2347-
// Use a non-null pointer value
2348-
// (self.ptr might be null because of wrapping)
2349-
Some(ptr::read(1 as *mut T))
2350-
} else {
2351-
let old = self.ptr;
2352-
self.ptr = self.ptr.offset(1);
2353-
2354-
Some(ptr::read(old))
2355-
}
2351+
let old = self.ptr;
2352+
self.ptr = self.ptr.offset(1);
2353+
2354+
Some(ptr::read(old))
23562355
}
23572356
}
23582357
}
@@ -2379,19 +2378,17 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
23792378
unsafe {
23802379
if self.end == self.ptr {
23812380
None
2382-
} else {
2383-
if mem::size_of::<T>() == 0 {
2384-
// See above for why 'ptr.offset' isn't used
2385-
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
2381+
} else if mem::size_of::<T>() == 0 {
2382+
// See above for why 'ptr.offset' isn't used
2383+
self.end = arith_offset(self.end as *const i8, -1) as *mut T;
23862384

2387-
// Use a non-null pointer value
2388-
// (self.end might be null because of wrapping)
2389-
Some(ptr::read(1 as *mut T))
2390-
} else {
2391-
self.end = self.end.offset(-1);
2385+
// Use a non-null pointer value
2386+
// (self.end might be null because of wrapping)
2387+
Some(ptr::read(1 as *mut T))
2388+
} else {
2389+
self.end = self.end.offset(-1);
23922390

2393-
Some(ptr::read(self.end))
2394-
}
2391+
Some(ptr::read(self.end))
23952392
}
23962393
}
23972394
}
@@ -2485,7 +2482,7 @@ impl<'a, T> DoubleEndedIterator for Drain<'a, T> {
24852482
impl<'a, T> Drop for Drain<'a, T> {
24862483
fn drop(&mut self) {
24872484
// exhaust self first
2488-
while let Some(_) = self.next() {}
2485+
for _ in self.by_ref() {}
24892486

24902487
if self.tail_len > 0 {
24912488
unsafe {

0 commit comments

Comments
 (0)