Skip to content

Commit 459d4de

Browse files
committed
Fix clippy issues
1 parent c01a29d commit 459d4de

File tree

11 files changed

+204
-143
lines changed

11 files changed

+204
-143
lines changed

.travis.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ matrix:
88
env: TARGET=x86_64-unknown-linux-gnu
99
script: sh ci/miri.sh
1010
- name: "rustfmt/clippy"
11-
env: TARGET=x86_64-unknown-linux-gnu
11+
env: TARGET=i586-unknown-linux-gnu
1212
script: sh ci/tools.sh
1313
- name: "docs"
1414
env: TARGET=x86_64-unknown-linux-gnu
@@ -34,21 +34,35 @@ matrix:
3434
- name: "x86_64-unknown-linux-gnu (Rust 1.29.0)"
3535
rust: stable
3636
env: TARGET=x86_64-unknown-linux-gnu
37+
- name: "i686-unknown-linux-gnu"
38+
env: TARGET=i686-unknown-linux-gnu CROSS=1
3739
- name: "x86_64-apple-darwin"
3840
env: TARGET=x86_64-apple-darwin
3941
os: osx
4042
osx_image: xcode10
43+
- name: "i686-apple-darwin"
44+
env: TARGET=i686-apple-darwin
45+
os: osx
46+
osx_image: xcode10
4147
- name: "x86_64-pc-windows-msvc"
4248
env: TARGET=x86_64-pc-windows-msvc
4349
os: windows
4450
- name: "x86_64-pc-windows-gnu"
4551
env: TARGET=x86_64-pc-windows-gnu CROSS=1
52+
- name: "i686-pc-windows-gnu"
53+
env: TARGET=i686-pc-windows-gnu CROSS=1
4654

4755
# Tier 2/3 targets:
4856
- name: "i586-unknown-linux-gnu (no SSE2)"
4957
env: TARGET=i586-unknown-linux-gnu CROSS=1
58+
- name: "armv7-unknown-linux-gnueabihf"
59+
env: TARGET=armv7-unknown-linux-gnueabihf CROSS=1
5060
- name: "aarch64-unknown-linux-gnu"
5161
env: TARGET=aarch64-unknown-linux-gnu CROSS=1
62+
63+
allow_failure:
64+
# FIXME:
65+
- name: "armv7-unknown-linux-gnueabihf"
5266

5367
install: travis_retry rustup target add "${TARGET}"
5468
script: sh ci/run.sh

ci/tools.sh

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ if retry rustup component add clippy ; then
3333
cargo clippy --all -- -D clippy::pedantic
3434
fi
3535

36+
if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
37+
if retry rustup component add clippy ; then
38+
cargo clippy --all --target=i586-unknown-linux-gnu -- -D clippy::pedantic
39+
fi
40+
fi
41+
3642
if command -v shellcheck ; then
3743
shellcheck --version
3844
shellcheck ci/*.sh

clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = [ "CppCon", "SwissTable", "SipHash", "HashDoS" ]

src/fx.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ pub struct FxHasher {
2626
}
2727

2828
#[cfg(target_pointer_width = "32")]
29-
const K: usize = 0x9e3779b9;
29+
const K: usize = 0x9e37_79b9;
3030
#[cfg(target_pointer_width = "64")]
31-
const K: usize = 0x517cc1b727220a95;
31+
const K: usize = 0x517c_c1b7_2722_0a95;
3232

3333
impl Default for FxHasher {
3434
#[inline]
35-
fn default() -> FxHasher {
36-
FxHasher { hash: 0 }
35+
fn default() -> Self {
36+
Self { hash: 0 }
3737
}
3838
}
3939

@@ -48,14 +48,16 @@ impl Hasher for FxHasher {
4848
#[inline]
4949
fn write(&mut self, mut bytes: &[u8]) {
5050
#[cfg(target_pointer_width = "32")]
51-
let read_usize = |bytes| NativeEndian::read_u32(bytes);
51+
#[allow(clippy::cast_possible_truncation)]
52+
let read_usize = |bytes| NativeEndian::read_u32(bytes) as usize;
5253
#[cfg(target_pointer_width = "64")]
53-
let read_usize = |bytes| NativeEndian::read_u64(bytes);
54+
#[allow(clippy::cast_possible_truncation)]
55+
let read_usize = |bytes| NativeEndian::read_u64(bytes) as usize;
5456

55-
let mut hash = FxHasher { hash: self.hash };
57+
let mut hash = Self { hash: self.hash };
5658
assert!(size_of::<usize>() <= 8);
5759
while bytes.len() >= size_of::<usize>() {
58-
hash.add_to_hash(read_usize(bytes) as usize);
60+
hash.add_to_hash(read_usize(bytes));
5961
bytes = &bytes[size_of::<usize>()..];
6062
}
6163
if (size_of::<usize>() > 4) && (bytes.len() >= 4) {
@@ -66,7 +68,7 @@ impl Hasher for FxHasher {
6668
hash.add_to_hash(NativeEndian::read_u16(bytes) as usize);
6769
bytes = &bytes[2..];
6870
}
69-
if (size_of::<usize>() > 1) && bytes.len() >= 1 {
71+
if (size_of::<usize>() > 1) && !bytes.is_empty() {
7072
hash.add_to_hash(bytes[0] as usize);
7173
}
7274
self.hash = hash.hash;
@@ -89,13 +91,15 @@ impl Hasher for FxHasher {
8991

9092
#[cfg(target_pointer_width = "32")]
9193
#[inline]
94+
#[allow(clippy::cast_possible_truncation)]
9295
fn write_u64(&mut self, i: u64) {
9396
self.add_to_hash(i as usize);
9497
self.add_to_hash((i >> 32) as usize);
9598
}
9699

97100
#[cfg(target_pointer_width = "64")]
98101
#[inline]
102+
#[allow(clippy::cast_possible_truncation)]
99103
fn write_u64(&mut self, i: u64) {
100104
self.add_to_hash(i as usize);
101105
}

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! map, adapted to make it a drop-in replacement for Rust's standard `HashMap`
33
//! and `HashSet` types.
44
//!
5-
//! The original C++ version of SwissTable can be found [here], and this
5+
//! The original C++ version of [SwissTable] can be found [here], and this
66
//! [CppCon talk] gives an overview of how the algorithm works.
77
//!
88
//! [SwissTable]: https://abseil.io/blog/20180927-swisstables
@@ -24,6 +24,7 @@
2424
)]
2525
#![warn(missing_docs)]
2626
#![cfg_attr(hashbrown_deny_warnings, deny(warnings))]
27+
#![allow(clippy::module_name_repetitions)]
2728

2829
#[cfg(test)]
2930
#[macro_use]
@@ -32,7 +33,6 @@ extern crate std;
3233
#[cfg(test)]
3334
extern crate rand;
3435

35-
3636
#[cfg(feature = "nightly")]
3737
#[cfg_attr(test, macro_use)]
3838
extern crate alloc;
@@ -87,7 +87,7 @@ pub mod hash_set {
8787
pub use map::HashMap;
8888
pub use set::HashSet;
8989

90-
/// Augments `AllocErr` with a CapacityOverflow variant.
90+
/// Augments `AllocErr` with a `CapacityOverflow` variant.
9191
#[derive(Clone, PartialEq, Eq, Debug)]
9292
pub enum CollectionAllocErr {
9393
/// Error due to the computed capacity exceeding the collection's maximum

src/map.rs

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use self::Entry::*;
2-
31
use core::borrow::Borrow;
42
use core::fmt::{self, Debug};
53
use core::hash::{BuildHasher, Hash, Hasher};
@@ -212,8 +210,8 @@ impl<K: Hash + Eq, V> HashMap<K, V, DefaultHashBuilder> {
212210
/// let mut map: HashMap<&str, i32> = HashMap::new();
213211
/// ```
214212
#[inline]
215-
pub fn new() -> HashMap<K, V, DefaultHashBuilder> {
216-
Default::default()
213+
pub fn new() -> Self {
214+
Self::default()
217215
}
218216

219217
/// Creates an empty `HashMap` with the specified capacity.
@@ -228,8 +226,8 @@ impl<K: Hash + Eq, V> HashMap<K, V, DefaultHashBuilder> {
228226
/// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
229227
/// ```
230228
#[inline]
231-
pub fn with_capacity(capacity: usize) -> HashMap<K, V, DefaultHashBuilder> {
232-
HashMap::with_capacity_and_hasher(capacity, Default::default())
229+
pub fn with_capacity(capacity: usize) -> Self {
230+
Self::with_capacity_and_hasher(capacity, DefaultHashBuilder::default())
233231
}
234232
}
235233

@@ -259,8 +257,8 @@ where
259257
/// map.insert(1, 2);
260258
/// ```
261259
#[inline]
262-
pub fn with_hasher(hash_builder: S) -> HashMap<K, V, S> {
263-
HashMap {
260+
pub fn with_hasher(hash_builder: S) -> Self {
261+
Self {
264262
hash_builder,
265263
table: RawTable::new(),
266264
}
@@ -288,8 +286,8 @@ where
288286
/// map.insert(1, 2);
289287
/// ```
290288
#[inline]
291-
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> HashMap<K, V, S> {
292-
HashMap {
289+
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self {
290+
Self {
293291
hash_builder,
294292
table: RawTable::with_capacity(capacity),
295293
}
@@ -1023,7 +1021,7 @@ where
10231021
V: PartialEq,
10241022
S: BuildHasher,
10251023
{
1026-
fn eq(&self, other: &HashMap<K, V, S>) -> bool {
1024+
fn eq(&self, other: &Self) -> bool {
10271025
if self.len() != other.len() {
10281026
return false;
10291027
}
@@ -1059,8 +1057,8 @@ where
10591057
{
10601058
/// Creates an empty `HashMap<K, V, S>`, with the `Default` value for the hasher.
10611059
#[inline]
1062-
fn default() -> HashMap<K, V, S> {
1063-
HashMap::with_hasher(Default::default())
1060+
fn default() -> Self {
1061+
Self::with_hasher(Default::default())
10641062
}
10651063
}
10661064

@@ -1245,7 +1243,7 @@ pub struct ValuesMut<'a, K: 'a, V: 'a> {
12451243
inner: IterMut<'a, K, V>,
12461244
}
12471245

1248-
/// A builder for computing where in a HashMap a key-value pair would be stored.
1246+
/// A builder for computing where in a [`HashMap`] a key-value pair would be stored.
12491247
///
12501248
/// See the [`HashMap::raw_entry_mut`] docs for usage examples.
12511249
///
@@ -1288,7 +1286,7 @@ pub struct RawVacantEntryMut<'a, K: 'a, V: 'a, S: 'a> {
12881286
hash_builder: &'a S,
12891287
}
12901288

1291-
/// A builder for computing where in a HashMap a key-value pair would be stored.
1289+
/// A builder for computing where in a [`HashMap`] a key-value pair would be stored.
12921290
///
12931291
/// See the [`HashMap::raw_entry`] docs for usage examples.
12941292
///
@@ -1304,6 +1302,7 @@ where
13041302
{
13051303
/// Create a `RawEntryMut` from the given key.
13061304
#[inline]
1305+
#[allow(clippy::wrong_self_convention)]
13071306
pub fn from_key<Q: ?Sized>(self, k: &Q) -> RawEntryMut<'a, K, V, S>
13081307
where
13091308
K: Borrow<Q>,
@@ -1316,6 +1315,7 @@ where
13161315

13171316
/// Create a `RawEntryMut` from the given key and its hash.
13181317
#[inline]
1318+
#[allow(clippy::wrong_self_convention)]
13191319
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, k: &Q) -> RawEntryMut<'a, K, V, S>
13201320
where
13211321
K: Borrow<Q>,
@@ -1343,6 +1343,7 @@ where
13431343

13441344
/// Create a `RawEntryMut` from the given hash.
13451345
#[inline]
1346+
#[allow(clippy::wrong_self_convention)]
13461347
pub fn from_hash<F>(self, hash: u64, is_match: F) -> RawEntryMut<'a, K, V, S>
13471348
where
13481349
for<'b> F: FnMut(&'b K) -> bool,
@@ -1357,6 +1358,7 @@ where
13571358
{
13581359
/// Access an entry by key.
13591360
#[inline]
1361+
#[allow(clippy::wrong_self_convention)]
13601362
pub fn from_key<Q: ?Sized>(self, k: &Q) -> Option<(&'a K, &'a V)>
13611363
where
13621364
K: Borrow<Q>,
@@ -1369,6 +1371,7 @@ where
13691371

13701372
/// Access an entry by a key and its hash.
13711373
#[inline]
1374+
#[allow(clippy::wrong_self_convention)]
13721375
pub fn from_key_hashed_nocheck<Q: ?Sized>(self, hash: u64, k: &Q) -> Option<(&'a K, &'a V)>
13731376
where
13741377
K: Borrow<Q>,
@@ -1393,6 +1396,7 @@ where
13931396

13941397
/// Access an entry by hash.
13951398
#[inline]
1399+
#[allow(clippy::wrong_self_convention)]
13961400
pub fn from_hash<F>(self, hash: u64, is_match: F) -> Option<(&'a K, &'a V)>
13971401
where
13981402
F: FnMut(&K) -> bool,
@@ -1614,6 +1618,7 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
16141618
/// Sets the value of the entry with the VacantEntry's key,
16151619
/// and returns a mutable reference to it.
16161620
#[inline]
1621+
#[allow(clippy::shadow_unrelated)]
16171622
pub fn insert_hashed_nocheck(self, hash: u64, key: K, value: V) -> (&'a mut K, &'a mut V)
16181623
where
16191624
K: Hash,
@@ -1683,8 +1688,8 @@ pub enum Entry<'a, K: 'a, V: 'a, S: 'a> {
16831688
impl<'a, K: 'a + Debug + Eq + Hash, V: 'a + Debug, S: 'a> Debug for Entry<'a, K, V, S> {
16841689
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16851690
match *self {
1686-
Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(),
1687-
Occupied(ref o) => f.debug_tuple("Entry").field(o).finish(),
1691+
Entry::Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(),
1692+
Entry::Occupied(ref o) => f.debug_tuple("Entry").field(o).finish(),
16881693
}
16891694
}
16901695
}
@@ -2007,8 +2012,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
20072012
S: BuildHasher,
20082013
{
20092014
match self {
2010-
Occupied(entry) => entry.into_mut(),
2011-
Vacant(entry) => entry.insert(default),
2015+
Entry::Occupied(entry) => entry.into_mut(),
2016+
Entry::Vacant(entry) => entry.insert(default),
20122017
}
20132018
}
20142019

@@ -2034,8 +2039,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
20342039
S: BuildHasher,
20352040
{
20362041
match self {
2037-
Occupied(entry) => entry.into_mut(),
2038-
Vacant(entry) => entry.insert(default()),
2042+
Entry::Occupied(entry) => entry.into_mut(),
2043+
Entry::Vacant(entry) => entry.insert(default()),
20392044
}
20402045
}
20412046

@@ -2052,8 +2057,8 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
20522057
#[inline]
20532058
pub fn key(&self) -> &K {
20542059
match *self {
2055-
Occupied(ref entry) => entry.key(),
2056-
Vacant(ref entry) => entry.key(),
2060+
Entry::Occupied(ref entry) => entry.key(),
2061+
Entry::Vacant(ref entry) => entry.key(),
20572062
}
20582063
}
20592064

@@ -2083,11 +2088,11 @@ impl<'a, K, V, S> Entry<'a, K, V, S> {
20832088
F: FnOnce(&mut V),
20842089
{
20852090
match self {
2086-
Occupied(mut entry) => {
2091+
Entry::Occupied(mut entry) => {
20872092
f(entry.get_mut());
2088-
Occupied(entry)
2093+
Entry::Occupied(entry)
20892094
}
2090-
Vacant(entry) => Vacant(entry),
2095+
Entry::Vacant(entry) => Entry::Vacant(entry),
20912096
}
20922097
}
20932098
}
@@ -2115,8 +2120,8 @@ impl<'a, K, V: Default, S> Entry<'a, K, V, S> {
21152120
S: BuildHasher,
21162121
{
21172122
match self {
2118-
Occupied(entry) => entry.into_mut(),
2119-
Vacant(entry) => entry.insert(Default::default()),
2123+
Entry::Occupied(entry) => entry.into_mut(),
2124+
Entry::Vacant(entry) => entry.insert(Default::default()),
21202125
}
21212126
}
21222127
}
@@ -2423,9 +2428,9 @@ where
24232428
S: BuildHasher + Default,
24242429
{
24252430
#[inline]
2426-
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> HashMap<K, V, S> {
2431+
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
24272432
let iter = iter.into_iter();
2428-
let mut map = HashMap::with_capacity_and_hasher(iter.size_hint().0, Default::default());
2433+
let mut map = Self::with_capacity_and_hasher(iter.size_hint().0, S::default());
24292434
for (k, v) in iter {
24302435
map.insert(k, v);
24312436
}

0 commit comments

Comments
 (0)