Skip to content

Commit 00ba2f9

Browse files
bors[bot]gnzlbg
andcommitted
Merge #52
52: Upgrade CI (clippy, more targets) r=Amanieu a=gnzlbg Co-authored-by: gnzlbg <[email protected]>
2 parents d40f49e + 1c6fcb9 commit 00ba2f9

14 files changed

+340
-179
lines changed

.travis.yml

+57-44
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,71 @@
11
language: rust
22
sudo: false
3+
rust: nightly
34

45
matrix:
56
include:
67
- name: "miri"
7-
rust: nightly
8-
install:
9-
- rustup component add rust-src
10-
- cargo +nightly install --force --git https://github.com/rust-lang/miri miri
11-
- cargo install xargo
12-
script:
13-
- cargo clean
14-
- cargo +nightly miri test
15-
- rust: 1.29.0
16-
- rust: stable
17-
- rust: beta
18-
- rust: nightly
19-
- rust: nightly
20-
env:
21-
- FEATURES='nightly'
8+
env: TARGET=x86_64-unknown-linux-gnu
9+
script: sh ci/miri.sh
10+
- name: "rustfmt/clippy"
11+
env: TARGET=i586-unknown-linux-gnu
12+
script: sh ci/tools.sh
13+
- name: "docs"
14+
env: TARGET=x86_64-unknown-linux-gnu
15+
script: cargo -vv doc --features nightly,serde,rayon
16+
deploy:
17+
provider: pages
18+
skip-cleanup: true
19+
github-token: $GITHUB_TOKEN
20+
local-dir: target/doc
21+
keep-history: false
22+
on:
23+
branch: master
2224

23-
# test a target without sse2 for raw/generic.rs
24-
- rust: stable
25-
env:
26-
- TARGET=i586-unknown-linux-gnu
27-
addons:
28-
apt:
29-
packages:
30-
- gcc-multilib
31-
install:
32-
- rustup target add $TARGET
33-
script:
34-
- cargo build --verbose --target $TARGET
35-
- cargo test --verbose --target $TARGET
25+
# Tier 1 targets:
26+
- name: "x86_64-unknown-linux-gnu"
27+
env: TARGET=x86_64-unknown-linux-gnu
28+
- name: "x86_64-unknown-linux-gnu (beta)"
29+
rust: beta
30+
env: TARGET=x86_64-unknown-linux-gnu
31+
- name: "x86_64-unknown-linux-gnu (stable)"
32+
rust: stable
33+
env: TARGET=x86_64-unknown-linux-gnu
34+
- name: "x86_64-unknown-linux-gnu (Rust 1.29.0)"
35+
rust: 1.31.0
36+
env: TARGET=x86_64-unknown-linux-gnu
37+
- name: "i686-unknown-linux-gnu"
38+
env: TARGET=i686-unknown-linux-gnu CROSS=1
39+
- name: "x86_64-apple-darwin"
40+
env: TARGET=x86_64-apple-darwin
41+
os: osx
42+
osx_image: xcode10
43+
- name: "i686-apple-darwin"
44+
env: TARGET=i686-apple-darwin
45+
os: osx
46+
osx_image: xcode10
47+
- name: "x86_64-pc-windows-msvc"
48+
env: TARGET=x86_64-pc-windows-msvc
49+
os: windows
50+
- name: "x86_64-pc-windows-gnu"
51+
env: TARGET=x86_64-pc-windows-gnu CROSS=1
52+
- name: "i686-pc-windows-gnu"
53+
env: TARGET=i686-pc-windows-gnu CROSS=1
54+
55+
# Tier 2/3 targets:
56+
- name: "i586-unknown-linux-gnu (no SSE2)"
57+
env: TARGET=i586-unknown-linux-gnu CROSS=1
58+
- name: "armv7-unknown-linux-gnueabihf"
59+
env: TARGET=armv7-unknown-linux-gnueabihf CROSS=1
60+
- name: "aarch64-unknown-linux-gnu"
61+
env: TARGET=aarch64-unknown-linux-gnu CROSS=1
62+
63+
install: travis_retry rustup target add "${TARGET}"
64+
script: sh ci/run.sh
3665

3766
branches:
3867
# Don't build these branches
3968
except:
4069
# Used by bors
4170
- trying.tmp
4271
- staging.tmp
43-
44-
before_script:
45-
- if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then rustup component add rustfmt; fi
46-
47-
script:
48-
- if [ "$TRAVIS_RUST_VERSION" == "stable" ]; then cargo fmt -- --check; fi
49-
50-
- cargo build --verbose --features "$FEATURES"
51-
- cargo test --verbose --features "$FEATURES"
52-
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo bench --verbose --features "$FEATURES"; fi
53-
- cargo doc --verbose --features "$FEATURES"
54-
55-
- cargo build --verbose --features "$FEATURES serde"
56-
- cargo test --verbose --features "$FEATURES serde"
57-
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo bench --verbose --features "$FEATURES serde"; fi
58-
- cargo doc --verbose --features "$FEATURES serde"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ rustc-hash = "1.0"
2626
serde_test = "1.0"
2727

2828
[features]
29+
default = []
2930
nightly = []

ci/miri.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
export CARGO_NET_RETRY=5
6+
export CARGO_NET_TIMEOUT=10
7+
8+
if cargo install --force --git https://github.com/rust-lang/miri miri ; then
9+
cargo miri setup
10+
cargo miri test
11+
fi

ci/run.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
: "${TARGET?The TARGET environment variable must be set.}"
6+
7+
FEATURES="rayon,serde"
8+
if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
9+
FEATURES="${FEATURES},nightly"
10+
export RUSTFLAGS="$RUSTFLAGS -D warnings"
11+
fi
12+
13+
CARGO=cargo
14+
if [ "${CROSS}" = "1" ]; then
15+
export CARGO_NET_RETRY=5
16+
export CARGO_NET_TIMEOUT=10
17+
18+
cargo install cross
19+
CARGO=cross
20+
fi
21+
22+
export RUSTFLAGS="$RUSTFLAGS --cfg hashbrown_deny_warnings"
23+
24+
"${CARGO}" -vv test --target="${TARGET}"
25+
"${CARGO}" -vv test --target="${TARGET}" --features "${FEATURES}"
26+
27+
"${CARGO}" -vv test --target="${TARGET}" --release
28+
"${CARGO}" -vv test --target="${TARGET}" --release --features "${FEATURES}"
29+
30+
if [ "${TRAVIS_RUST_VERSION}" = "nightly" ]; then
31+
# Run benchmark on native targets, build them on non-native ones:
32+
NO_RUN=""
33+
if [ "${CROSS}" = "1" ]; then
34+
NO_RUN="--no-run"
35+
fi
36+
37+
"${CARGO}" -vv bench "${NO_RUN}" --features "${FEATURES}"
38+
fi

ci/tools.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
retry() {
6+
result=0
7+
count=1
8+
max=5
9+
while [ "$count" -le 3 ]; do
10+
[ "$result" -ne 0 ] && {
11+
printf "\nRetrying, %d of %d\n" $count $max >&2
12+
}
13+
"$@"
14+
result=$?
15+
[ $result -eq 0 ] && break
16+
count=$(count + 1)
17+
sleep 1
18+
done
19+
20+
[ "$count" -gt 3 ] && {
21+
printf "\nFailed %d times.\n" $max >&2
22+
}
23+
24+
return $result
25+
}
26+
27+
28+
if retry rustup component add rustfmt ; then
29+
cargo fmt --all -- --check
30+
fi
31+
32+
if retry rustup component add clippy ; then
33+
cargo clippy --all -- -D clippy::pedantic
34+
fi
35+
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+
42+
if command -v shellcheck ; then
43+
shellcheck --version
44+
shellcheck ci/*.sh
45+
fi

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

+4-2
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
@@ -23,9 +23,11 @@
2323
)
2424
)]
2525
#![warn(missing_docs)]
26+
#![allow(clippy::module_name_repetitions)]
2627

2728
#[cfg(test)]
2829
#[macro_use]
30+
#[allow(unused_imports)]
2931
extern crate std;
3032
#[cfg(test)]
3133
extern crate rand;
@@ -84,7 +86,7 @@ pub mod hash_set {
8486
pub use map::HashMap;
8587
pub use set::HashSet;
8688

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

0 commit comments

Comments
 (0)