Skip to content

Commit cc852e7

Browse files
authored
Address unexpected_cfg lints. (#269)
Replace `cfg(feature = "$X")` with `cfg($X)` for each undeclared feature X. Declare each such cfg in build.rs. This silences the warnings in recent toolchains.
1 parent 7dbeb5b commit cc852e7

File tree

10 files changed

+42
-40
lines changed

10 files changed

+42
-40
lines changed

build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ use std::env;
44

55
fn main() {
66
println!("cargo:rerun-if-changed=build.rs");
7+
println!("cargo:rustc-check-cfg=cfg(specialize)");
78
if let Some(true) = version_check::supports_feature("specialize") {
8-
println!("cargo:rustc-cfg=feature=\"specialize\"");
9+
println!("cargo:rustc-cfg=specialize");
910
}
1011
let arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH was not set");
12+
println!("cargo:rustc-check-cfg=cfg(folded_multiply)");
1113
if arch.eq_ignore_ascii_case("x86_64")
1214
|| arch.eq_ignore_ascii_case("aarch64")
1315
|| arch.eq_ignore_ascii_case("mips64")
1416
|| arch.eq_ignore_ascii_case("powerpc64")
1517
|| arch.eq_ignore_ascii_case("riscv64gc")
1618
|| arch.eq_ignore_ascii_case("s390x")
1719
{
18-
println!("cargo:rustc-cfg=feature=\"folded_multiply\"");
20+
println!("cargo:rustc-cfg=folded_multiply");
1921
}
2022
}

src/aes_hash.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl AHasher {
9494
}
9595

9696
#[inline]
97-
#[cfg(feature = "specialize")]
97+
#[cfg(specialize)]
9898
fn short_finish(&self) -> u64 {
9999
let combined = aesenc(self.sum, self.enc);
100100
let result: [u64; 2] = aesdec(combined, combined).convert();
@@ -214,14 +214,14 @@ impl Hasher for AHasher {
214214
}
215215
}
216216

217-
#[cfg(feature = "specialize")]
217+
#[cfg(specialize)]
218218
pub(crate) struct AHasherU64 {
219219
pub(crate) buffer: u64,
220220
pub(crate) pad: u64,
221221
}
222222

223223
/// A specialized hasher for only primitives under 64 bits.
224-
#[cfg(feature = "specialize")]
224+
#[cfg(specialize)]
225225
impl Hasher for AHasherU64 {
226226
#[inline]
227227
fn finish(&self) -> u64 {
@@ -264,11 +264,11 @@ impl Hasher for AHasherU64 {
264264
}
265265
}
266266

267-
#[cfg(feature = "specialize")]
267+
#[cfg(specialize)]
268268
pub(crate) struct AHasherFixed(pub AHasher);
269269

270270
/// A specialized hasher for fixed size primitives larger than 64 bits.
271-
#[cfg(feature = "specialize")]
271+
#[cfg(specialize)]
272272
impl Hasher for AHasherFixed {
273273
#[inline]
274274
fn finish(&self) -> u64 {
@@ -311,12 +311,12 @@ impl Hasher for AHasherFixed {
311311
}
312312
}
313313

314-
#[cfg(feature = "specialize")]
314+
#[cfg(specialize)]
315315
pub(crate) struct AHasherStr(pub AHasher);
316316

317317
/// A specialized hasher for strings
318318
/// Note that the other types don't panic because the hash impl for String tacks on an unneeded call. (As does vec)
319-
#[cfg(feature = "specialize")]
319+
#[cfg(specialize)]
320320
impl Hasher for AHasherStr {
321321
#[inline]
322322
fn finish(&self) -> u64 {

src/fallback_hash.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl AHasher {
115115
}
116116

117117
#[inline]
118-
#[cfg(feature = "specialize")]
118+
#[cfg(specialize)]
119119
fn short_finish(&self) -> u64 {
120120
folded_multiply(self.buffer, self.pad)
121121
}
@@ -199,14 +199,14 @@ impl Hasher for AHasher {
199199
}
200200
}
201201

202-
#[cfg(feature = "specialize")]
202+
#[cfg(specialize)]
203203
pub(crate) struct AHasherU64 {
204204
pub(crate) buffer: u64,
205205
pub(crate) pad: u64,
206206
}
207207

208208
/// A specialized hasher for only primitives under 64 bits.
209-
#[cfg(feature = "specialize")]
209+
#[cfg(specialize)]
210210
impl Hasher for AHasherU64 {
211211
#[inline]
212212
fn finish(&self) -> u64 {
@@ -250,11 +250,11 @@ impl Hasher for AHasherU64 {
250250
}
251251
}
252252

253-
#[cfg(feature = "specialize")]
253+
#[cfg(specialize)]
254254
pub(crate) struct AHasherFixed(pub AHasher);
255255

256256
/// A specialized hasher for fixed size primitives larger than 64 bits.
257-
#[cfg(feature = "specialize")]
257+
#[cfg(specialize)]
258258
impl Hasher for AHasherFixed {
259259
#[inline]
260260
fn finish(&self) -> u64 {
@@ -297,12 +297,12 @@ impl Hasher for AHasherFixed {
297297
}
298298
}
299299

300-
#[cfg(feature = "specialize")]
300+
#[cfg(specialize)]
301301
pub(crate) struct AHasherStr(pub AHasher);
302302

303303
/// A specialized hasher for a single string
304304
/// Note that the other types don't panic because the hash impl for String tacks on an unneeded call. (As does vec)
305-
#[cfg(feature = "specialize")]
305+
#[cfg(specialize)]
306306
impl Hasher for AHasherStr {
307307
#[inline]
308308
fn finish(&self) -> u64 {

src/hash_quality_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ mod fallback_tests {
407407
#[test]
408408
fn fallback_keys_affect_every_byte() {
409409
//For fallback second key is not used in every hash.
410-
#[cfg(all(not(feature = "specialize"), feature = "folded_multiply"))]
410+
#[cfg(all(not(specialize), folded_multiply))]
411411
test_keys_affect_every_byte(0, |a, b| AHasher::new_with_keys(a ^ b, a));
412412
test_keys_affect_every_byte("", |a, b| AHasher::new_with_keys(a ^ b, a));
413413
test_keys_affect_every_byte((0, 0), |a, b| AHasher::new_with_keys(a ^ b, a));
@@ -504,7 +504,7 @@ mod aes_tests {
504504

505505
#[test]
506506
fn aes_keys_affect_every_byte() {
507-
#[cfg(not(feature = "specialize"))]
507+
#[cfg(not(specialize))]
508508
test_keys_affect_every_byte(0, AHasher::test_with_keys);
509509
test_keys_affect_every_byte("", AHasher::test_with_keys);
510510
test_keys_affect_every_byte((0, 0), AHasher::test_with_keys);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Note the import of [HashMapExt]. This is needed for the constructor.
9797
#![deny(clippy::correctness, clippy::complexity, clippy::perf)]
9898
#![allow(clippy::pedantic, clippy::cast_lossless, clippy::unreadable_literal)]
9999
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
100-
#![cfg_attr(feature = "specialize", feature(min_specialization))]
100+
#![cfg_attr(specialize, feature(min_specialization))]
101101
#![cfg_attr(feature = "nightly-arm-aes", feature(stdarch_arm_neon_intrinsics))]
102102

103103
#[macro_use]

src/operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ const SHUFFLE_MASK: u128 = 0x020a0700_0c01030e_050f0d08_06090b04_u128;
1313
//const SHUFFLE_MASK: u128 = 0x040A0700_030E0106_0D050F08_020B0C09_u128;
1414

1515
#[inline(always)]
16-
#[cfg(feature = "folded_multiply")]
16+
#[cfg(folded_multiply)]
1717
pub(crate) const fn folded_multiply(s: u64, by: u64) -> u64 {
1818
let result = (s as u128).wrapping_mul(by as u128);
1919
((result & 0xffff_ffff_ffff_ffff) as u64) ^ ((result >> 64) as u64)
2020
}
2121

2222
#[inline(always)]
23-
#[cfg(not(feature = "folded_multiply"))]
23+
#[cfg(not(folded_multiply))]
2424
pub(crate) const fn folded_multiply(s: u64, by: u64) -> u64 {
2525
let b1 = s.wrapping_mul(by.swap_bytes());
2626
let b2 = s.swap_bytes().wrapping_mul(!by);

src/random_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,14 @@ impl BuildHasher for RandomState {
453453
/// implementation of [`Hash`]. The way to create a combined hash of
454454
/// multiple values is to call [`Hash::hash`] multiple times using the same
455455
/// [`Hasher`], not to call this method repeatedly and combine the results.
456-
#[cfg(feature = "specialize")]
456+
#[cfg(specialize)]
457457
#[inline]
458458
fn hash_one<T: Hash>(&self, x: T) -> u64 {
459459
RandomState::hash_one(self, x)
460460
}
461461
}
462462

463-
#[cfg(feature = "specialize")]
463+
#[cfg(specialize)]
464464
impl RandomState {
465465
#[inline]
466466
pub(crate) fn hash_as_u64<T: Hash + ?Sized>(&self, value: &T) -> u64 {

src/specialize.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ extern crate alloc;
88
#[cfg(feature = "std")]
99
extern crate std as alloc;
1010

11-
#[cfg(feature = "specialize")]
11+
#[cfg(specialize)]
1212
use alloc::string::String;
13-
#[cfg(feature = "specialize")]
13+
#[cfg(specialize)]
1414
use alloc::vec::Vec;
1515

1616
/// Provides a way to get an optimized hasher for a given data type.
@@ -20,7 +20,7 @@ pub(crate) trait CallHasher {
2020
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64;
2121
}
2222

23-
#[cfg(not(feature = "specialize"))]
23+
#[cfg(not(specialize))]
2424
impl<T> CallHasher for T
2525
where
2626
T: Hash + ?Sized,
@@ -33,7 +33,7 @@ where
3333
}
3434
}
3535

36-
#[cfg(feature = "specialize")]
36+
#[cfg(specialize)]
3737
impl<T> CallHasher for T
3838
where
3939
T: Hash + ?Sized,
@@ -48,7 +48,7 @@ where
4848

4949
macro_rules! call_hasher_impl_u64 {
5050
($typ:ty) => {
51-
#[cfg(feature = "specialize")]
51+
#[cfg(specialize)]
5252
impl CallHasher for $typ {
5353
#[inline]
5454
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
@@ -76,7 +76,7 @@ call_hasher_impl_u64!(&i64);
7676

7777
macro_rules! call_hasher_impl_fixed_length{
7878
($typ:ty) => {
79-
#[cfg(feature = "specialize")]
79+
#[cfg(specialize)]
8080
impl CallHasher for $typ {
8181
#[inline]
8282
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
@@ -95,31 +95,31 @@ call_hasher_impl_fixed_length!(&i128);
9595
call_hasher_impl_fixed_length!(&usize);
9696
call_hasher_impl_fixed_length!(&isize);
9797

98-
#[cfg(feature = "specialize")]
98+
#[cfg(specialize)]
9999
impl CallHasher for [u8] {
100100
#[inline]
101101
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
102102
random_state.hash_as_str(value)
103103
}
104104
}
105105

106-
#[cfg(feature = "specialize")]
106+
#[cfg(specialize)]
107107
impl CallHasher for Vec<u8> {
108108
#[inline]
109109
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
110110
random_state.hash_as_str(value)
111111
}
112112
}
113113

114-
#[cfg(feature = "specialize")]
114+
#[cfg(specialize)]
115115
impl CallHasher for str {
116116
#[inline]
117117
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
118118
random_state.hash_as_str(value)
119119
}
120120
}
121121

122-
#[cfg(all(feature = "specialize"))]
122+
#[cfg(all(specialize))]
123123
impl CallHasher for String {
124124
#[inline]
125125
fn get_hash<H: Hash + ?Sized>(value: &H, random_state: &RandomState) -> u64 {
@@ -133,7 +133,7 @@ mod test {
133133
use crate::*;
134134

135135
#[test]
136-
#[cfg(feature = "specialize")]
136+
#[cfg(specialize)]
137137
pub fn test_specialized_invoked() {
138138
let build_hasher = RandomState::with_seeds(1, 2, 3, 4);
139139
let shortened = u64::get_hash(&0, &build_hasher);
@@ -185,7 +185,7 @@ mod test {
185185
str::get_hash(&"test", &build_hasher),
186186
String::get_hash(&"test".to_string(), &build_hasher)
187187
);
188-
#[cfg(feature = "specialize")]
188+
#[cfg(specialize)]
189189
assert_eq!(
190190
str::get_hash(&"test", &build_hasher),
191191
<[u8]>::get_hash("test".as_bytes(), &build_hasher)
@@ -205,7 +205,7 @@ mod test {
205205
str::get_hash(&&"test", &build_hasher),
206206
String::get_hash(&"test".to_string(), &build_hasher)
207207
);
208-
#[cfg(feature = "specialize")]
208+
#[cfg(specialize)]
209209
assert_eq!(
210210
str::get_hash(&&"test", &build_hasher),
211211
<[u8]>::get_hash(&"test".to_string().into_bytes(), &build_hasher)

tests/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]
1+
#![cfg_attr(specialize, feature(build_hasher_simple_hash_one))]
22

33
use ahash::{AHasher, RandomState};
44
use criterion::*;

tests/map_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "specialize", feature(build_hasher_simple_hash_one))]
1+
#![cfg_attr(specialize, feature(build_hasher_simple_hash_one))]
22

33
use std::hash::{BuildHasher, Hash, Hasher};
44

@@ -151,13 +151,13 @@ fn check_for_collisions<H: Hash, B: BuildHasher>(build_hasher: &B, items: &[H],
151151
);
152152
}
153153

154-
#[cfg(feature = "specialize")]
154+
#[cfg(specialize)]
155155
#[allow(unused)] // False positive
156156
fn hash<H: Hash, B: BuildHasher>(b: &H, build_hasher: &B) -> u64 {
157157
build_hasher.hash_one(b)
158158
}
159159

160-
#[cfg(not(feature = "specialize"))]
160+
#[cfg(not(specialize))]
161161
#[allow(unused)] // False positive
162162
fn hash<H: Hash, B: BuildHasher>(b: &H, build_hasher: &B) -> u64 {
163163
let mut hasher = build_hasher.build_hasher();

0 commit comments

Comments
 (0)