diff --git a/.gitignore b/.gitignore index 57407a2399a2f..e002b987e1ee2 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/etc/char_private.py b/src/etc/char_private.py index cfe5b01e934e7..a0bfa5a4d4534 100644 --- a/src/etc/char_private.py +++ b/src/etc/char_private.py @@ -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("];") @@ -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 { @@ -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 {\ """) diff --git a/src/etc/dec2flt_table.py b/src/etc/dec2flt_table.py index 9fdab1fcfca28..ffadd307f4f91 100644 --- a/src/etc/dec2flt_table.py +++ b/src/etc/dec2flt_table.py @@ -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))] """ diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index c2a8f5f8ff957..f70c5259a04e6 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -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 @@ -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) } } @@ -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) } } diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 844b70835936f..ed4bd188d66e5 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -1095,7 +1095,7 @@ impl Clone for Weak { } } - return Weak { ptr: self.ptr }; + Weak { ptr: self.ptr } } } diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6f125cdba8190..58e7b6a1b2627 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -120,7 +120,7 @@ pub struct Box(Unique); /// 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 diff --git a/src/liballoc/clippy.toml b/src/liballoc/clippy.toml new file mode 100644 index 0000000000000..4b496470d8964 --- /dev/null +++ b/src/liballoc/clippy.toml @@ -0,0 +1 @@ +doc-valid-idents = ["TimSort"] diff --git a/src/liballoc/linked_list.rs b/src/liballoc/linked_list.rs index 3ac5a85d721a1..ef4f944329f9e 100644 --- a/src/liballoc/linked_list.rs +++ b/src/liballoc/linked_list.rs @@ -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, diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index dbf1fb1367dda..cf01789ca54f6 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -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. /// diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 7fa872f4ded57..e1d7a8f9977f2 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -27,7 +27,7 @@ //! We can explicitly specify `hello_world`'s lifetime as well: //! //! ``` -//! let hello_world: &'static str = "Hello, world!"; +//! let hello_world: &str = "Hello, world!"; //! ``` //! //! *[See also the `str` primitive type](../../std/primitive.str.html).* @@ -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`]. diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index ca493ab27e3ad..146b4a153a2b6 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -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); @@ -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] @@ -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] @@ -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] @@ -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")] @@ -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 { diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index a14a5d32738b3..37e82c20bb85f 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -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 \ diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 93d7e66b7b203..96f7c9f8df93a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -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 { #[inline] fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] } @@ -2337,22 +2338,20 @@ impl Iterator for IntoIter { unsafe { if self.ptr as *const _ == self.end { None + } else if mem::size_of::() == 0 { + // purposefully don't use 'ptr.offset' because for + // vectors with 0-size elements this would return the + // same pointer. + self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T; + + // Use a non-null pointer value + // (self.ptr might be null because of wrapping) + Some(ptr::read(1 as *mut T)) } else { - if mem::size_of::() == 0 { - // purposefully don't use 'ptr.offset' because for - // vectors with 0-size elements this would return the - // same pointer. - self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T; - - // Use a non-null pointer value - // (self.ptr might be null because of wrapping) - Some(ptr::read(1 as *mut T)) - } else { - let old = self.ptr; - self.ptr = self.ptr.offset(1); - - Some(ptr::read(old)) - } + let old = self.ptr; + self.ptr = self.ptr.offset(1); + + Some(ptr::read(old)) } } } @@ -2379,19 +2378,17 @@ impl DoubleEndedIterator for IntoIter { unsafe { if self.end == self.ptr { None - } else { - if mem::size_of::() == 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::() == 0 { + // See above for why 'ptr.offset' isn't used + self.end = arith_offset(self.end as *const i8, -1) as *mut T; - // Use a non-null pointer value - // (self.end might be null because of wrapping) - Some(ptr::read(1 as *mut T)) - } else { - self.end = self.end.offset(-1); + // Use a non-null pointer value + // (self.end might be null because of wrapping) + Some(ptr::read(1 as *mut T)) + } else { + self.end = self.end.offset(-1); - Some(ptr::read(self.end)) - } + Some(ptr::read(self.end)) } } } @@ -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() {} if self.tail_len > 0 { unsafe { diff --git a/src/liballoc/vec_deque.rs b/src/liballoc/vec_deque.rs index f56aa23a4eb2f..623ff9e3dbf9a 100644 --- a/src/liballoc/vec_deque.rs +++ b/src/liballoc/vec_deque.rs @@ -1621,7 +1621,7 @@ impl VecDeque { } } - return elem; + elem } /// Splits the collection into two at the given index. @@ -2479,54 +2479,52 @@ impl From> for Vec { // 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) { + // 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 { + // right hand block is the long one; move that enough for the left + ptr::copy(buf.offset(tail as isize), + buf.offset((tail - head) as isize), + cap - tail); + // copy left in the end + ptr::copy(buf, buf.offset((cap - head) as isize), head); + // shift the new thing to the start + ptr::copy(buf.offset((tail - head) as isize), buf, len); + } else { + // left hand block is the long one, we can do it in two! + ptr::copy(buf, buf.offset((cap - tail) as isize), head); + ptr::copy(buf.offset(tail as isize), buf, cap - tail); + } } 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 { - // right hand block is the long one; move that enough for the left - ptr::copy(buf.offset(tail as isize), - buf.offset((tail - head) as isize), - cap - tail); - // copy left in the end - ptr::copy(buf, buf.offset((cap - head) as isize), head); - // shift the new thing to the start - ptr::copy(buf.offset((tail - head) as isize), buf, len); - } else { - // left hand block is the long one, we can do it in two! - ptr::copy(buf, buf.offset((cap - tail) as isize), head); - ptr::copy(buf.offset(tail as isize), buf, cap - tail); + // Need to use N swaps to move the ring + // We can use the space at the end of the ring as a temp store + + let mut left_edge: usize = 0; + let mut right_edge: usize = tail; + + // The general problem looks like this + // GHIJKLM...ABCDEF - before any swaps + // ABCDEFM...GHIJKL - after 1 pass of swaps + // ABCDEFGHIJM...KL - swap until the left edge reaches the temp store + // - then restart the algorithm with a new (smaller) store + // Sometimes the temp store is reached when the right edge is at the end + // of the buffer - this means we've hit the right order with fewer swaps! + // E.g + // EF..ABCD + // ABCDEF.. - after four only swaps we've finished + + while left_edge < len && right_edge != cap { + let mut right_offset = 0; + for i in left_edge..right_edge { + right_offset = (i - left_edge) % (cap - right_edge); + let src: isize = (right_edge + right_offset) as isize; + ptr::swap(buf.offset(i as isize), buf.offset(src)); } - } else { - // Need to use N swaps to move the ring - // We can use the space at the end of the ring as a temp store - - let mut left_edge: usize = 0; - let mut right_edge: usize = tail; - - // The general problem looks like this - // GHIJKLM...ABCDEF - before any swaps - // ABCDEFM...GHIJKL - after 1 pass of swaps - // ABCDEFGHIJM...KL - swap until the left edge reaches the temp store - // - then restart the algorithm with a new (smaller) store - // Sometimes the temp store is reached when the right edge is at the end - // of the buffer - this means we've hit the right order with fewer swaps! - // E.g - // EF..ABCD - // ABCDEF.. - after four only swaps we've finished - - while left_edge < len && right_edge != cap { - let mut right_offset = 0; - for i in left_edge..right_edge { - right_offset = (i - left_edge) % (cap - right_edge); - let src: isize = (right_edge + right_offset) as isize; - ptr::swap(buf.offset(i as isize), buf.offset(src)); - } - let n_ops = right_edge - left_edge; - left_edge += n_ops; - right_edge += right_offset + 1; + let n_ops = right_edge - left_edge; + left_edge += n_ops; + right_edge += right_offset + 1; - } } } diff --git a/src/libcore/char.rs b/src/libcore/char.rs index e8b81db07067c..37a338efce1cd 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -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), } } diff --git a/src/libcore/char_private.rs b/src/libcore/char_private.rs index e6803745ab543..8f73b4d1f7e13 100644 --- a/src/libcore/char_private.rs +++ b/src/libcore/char_private.rs @@ -8,8 +8,8 @@ // 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 { @@ -47,12 +47,13 @@ fn check(x: u16, singletonuppers: &[(u8, u8)], singletonlowers: &[u8], 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 { if 0x2a6d7 <= x && x < 0x2a700 { @@ -80,7 +81,7 @@ pub(crate) fn is_printable(x: char) -> bool { } } -const SINGLETONS0U: &'static [(u8, u8)] = &[ +const SINGLETONS0U: &[(u8, u8)] = &[ (0x00, 1), (0x03, 5), (0x05, 8), @@ -123,7 +124,7 @@ const SINGLETONS0U: &'static [(u8, u8)] = &[ (0xfe, 3), (0xff, 9), ]; -const SINGLETONS0L: &'static [u8] = &[ +const SINGLETONS0L: &[u8] = &[ 0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x60, 0x88, 0x8b, 0x8c, 0x90, 0x1c, 0x1d, 0xdd, 0x0e, 0x0f, 0x4b, 0x4c, 0x2e, 0x2f, 0x3f, @@ -163,7 +164,7 @@ const SINGLETONS0L: &'static [u8] = &[ 0x90, 0x91, 0xfe, 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7, 0xfe, 0xff, ]; -const SINGLETONS1U: &'static [(u8, u8)] = &[ +const SINGLETONS1U: &[(u8, u8)] = &[ (0x00, 6), (0x01, 1), (0x03, 1), @@ -198,7 +199,7 @@ const SINGLETONS1U: &'static [(u8, u8)] = &[ (0xf1, 1), (0xf9, 1), ]; -const SINGLETONS1L: &'static [u8] = &[ +const SINGLETONS1L: &[u8] = &[ 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, 0x09, 0x36, 0x3d, 0x3e, 0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x56, @@ -219,7 +220,7 @@ const SINGLETONS1L: &'static [u8] = &[ 0x6b, 0x73, 0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, 0x2f, 0x3f, ]; -const NORMAL0: &'static [u8] = &[ +const NORMAL0: &[u8] = &[ 0x00, 0x20, 0x5f, 0x22, 0x82, 0xdf, 0x04, @@ -368,7 +369,7 @@ const NORMAL0: &'static [u8] = &[ 0x1b, 0x03, 0x0f, 0x0d, ]; -const NORMAL1: &'static [u8] = &[ +const NORMAL1: &[u8] = &[ 0x5e, 0x22, 0x7b, 0x05, 0x03, 0x04, diff --git a/src/libcore/clippy.toml b/src/libcore/clippy.toml new file mode 100644 index 0000000000000..31b1d6d4b4792 --- /dev/null +++ b/src/libcore/clippy.toml @@ -0,0 +1 @@ +doc-valid-idents = ["BlockQuicksort", "SipHash"] diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 0f541a4b53789..fc374506e96aa 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1304,7 +1304,7 @@ impl<'a> Formatter<'a> { for part in formatted.parts { match *part { flt2dec::Part::Zero(mut nzeroes) => { - const ZEROES: &'static str = // 64 zeroes + const ZEROES: &str = // 64 zeroes "0000000000000000000000000000000000000000000000000000000000000000"; while nzeroes > ZEROES.len() { self.buf.write_str(ZEROES)?; diff --git a/src/libcore/fmt/num.rs b/src/libcore/fmt/num.rs index ee989854a3772..448496d87a1cb 100644 --- a/src/libcore/fmt/num.rs +++ b/src/libcore/fmt/num.rs @@ -186,7 +186,7 @@ integer! { i32, u32 } integer! { i64, u64 } integer! { i128, u128 } -const DEC_DIGITS_LUT: &'static[u8] = +const DEC_DIGITS_LUT: &[u8] = b"0001020304050607080910111213141516171819\ 2021222324252627282930313233343536373839\ 4041424344454647484950515253545556575859\ @@ -215,9 +215,9 @@ macro_rules! impl_Display { // need at least 16 bits for the 4-characters-at-a-time to work. if ::mem::size_of::<$t>() >= 2 { // eagerly decode 4 characters at a time - while n >= 10000 { - let rem = (n % 10000) as isize; - n /= 10000; + while n >= 10_000 { + let rem = (n % 10_000) as isize; + n /= 10_000; let d1 = (rem / 100) << 1; let d2 = (rem % 100) << 1; diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index 4e4d9b3f1e2f0..12e68d8532643 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -103,7 +103,7 @@ macro_rules! compress { /// `copy_nonoverlapping` to let the compiler generate the most efficient way /// to load it from a possibly unaligned address. /// -/// Unsafe because: unchecked indexing at i..i+size_of(int_ty) +/// Unsafe because: unchecked indexing at `i..i+size_of(int_ty)` macro_rules! load_int_le { ($buf:expr, $i:expr, $int_ty:ident) => ({ @@ -228,10 +228,10 @@ impl Hasher { #[inline] fn reset(&mut self) { self.length = 0; - self.state.v0 = self.k0 ^ 0x736f6d6570736575; - self.state.v1 = self.k1 ^ 0x646f72616e646f6d; - self.state.v2 = self.k0 ^ 0x6c7967656e657261; - self.state.v3 = self.k1 ^ 0x7465646279746573; + self.state.v0 = self.k0 ^ 0x736f_6d65_7073_6575; + self.state.v1 = self.k1 ^ 0x646f_7261_6e64_6f6d; + self.state.v2 = self.k0 ^ 0x6c79_6765_6e65_7261; + self.state.v3 = self.k1 ^ 0x7465_6462_7974_6573; self.ntail = 0; } @@ -331,7 +331,7 @@ impl super::Hasher for Hasher { if self.ntail != 0 { needed = 8 - self.ntail; - self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail; + self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << (8 * self.ntail); if length < needed { self.ntail += length; return diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 11e668d228c48..412200e83e937 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -965,7 +965,7 @@ pub trait FusedIterator: Iterator {} #[unstable(feature = "fused", issue = "35602")] impl<'a, I: FusedIterator + ?Sized> FusedIterator for &'a mut I {} -/// An iterator that reports an accurate length using size_hint. +/// An iterator that reports an accurate length using `size_hint`. /// /// The iterator reports a size hint where it is either exact /// (lower bound is equal to upper bound), or the upper bound is [`None`]. diff --git a/src/libcore/num/dec2flt/table.rs b/src/libcore/num/dec2flt/table.rs index cb8c94313d030..12abe5f164863 100644 --- a/src/libcore/num/dec2flt/table.rs +++ b/src/libcore/num/dec2flt/table.rs @@ -10,6 +10,7 @@ //! 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))] pub const MIN_E: i16 = -305; pub const MAX_E: i16 = 305; diff --git a/src/libcore/slice/sort.rs b/src/libcore/slice/sort.rs index 518d56095d601..1b5d6aee53711 100644 --- a/src/libcore/slice/sort.rs +++ b/src/libcore/slice/sort.rs @@ -11,7 +11,7 @@ //! Slice sorting //! //! This module contains an sort algorithm based on Orson Peters' pattern-defeating quicksort, -//! published at: https://github.com/orlp/pdqsort +//! published [on GitHub](https://github.com/orlp/pdqsort). //! //! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our //! stable sorting implementation. diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 1ca995cae6d97..1ccce9c55513f 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -10,7 +10,7 @@ //! String manipulation //! -//! For more details, see std::str +//! For more details, see [`std::str`](../../std/str/index.html). #![stable(feature = "rust1", since = "1.0.0")] @@ -852,6 +852,7 @@ macro_rules! derive_pattern_clone { /// For all patterns `P: Pattern<'a>` the following items will be /// generated (generics omitted): /// +/// ```ignore (pseudo-rust) /// struct $forward_iterator($internal_iterator); /// struct $reverse_iterator($internal_iterator); /// @@ -869,9 +870,10 @@ macro_rules! derive_pattern_clone { /// impl DoubleEndedIterator for $reverse_iterator /// where P::Searcher: DoubleEndedSearcher /// { /* internal ends up calling Searcher::next_match() */ } +/// ``` /// /// The internal one is defined outside the macro, and has almost the same -/// semantic as a DoubleEndedIterator by delegating to `pattern::Searcher` and +/// semantic as a `DoubleEndedIterator` by delegating to `pattern::Searcher` and /// `pattern::ReverseSearcher` for both forward and reverse iteration. /// /// "Almost", because a `Searcher` and a `ReverseSearcher` for a given @@ -1412,7 +1414,7 @@ Section: UTF-8 validation */ // use truncation to fit u64 into usize -const NONASCII_MASK: usize = 0x80808080_80808080u64 as usize; +const NONASCII_MASK: usize = 0x8080_8080_8080_8080u64 as usize; /// Returns `true` if any byte in the word `x` is nonascii (>= 128). #[inline] @@ -1566,12 +1568,12 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [ #[unstable(feature = "str_internals", issue = "0")] #[inline] pub fn utf8_char_width(b: u8) -> usize { - return UTF8_CHAR_WIDTH[b as usize] as usize; + UTF8_CHAR_WIDTH[b as usize] as usize } /// Mask of the value bits of a continuation byte. const CONT_MASK: u8 = 0b0011_1111; -/// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte. +/// Value of the tag bits (tag mask is `!CONT_MASK`) of a continuation byte. const TAG_CONT_U8: u8 = 0b1000_0000; /*