Skip to content

Commit c25f26d

Browse files
committed
Auto merge of rust-lang#5411 - dtolnay:hasher, r=flip1995
Downgrade implicit_hasher to pedantic From the [documentation](https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher), this lint is intended to suggest: ```diff - pub fn foo(map: &mut HashMap<i32, i32>) { } + pub fn foo<S: BuildHasher>(map: &mut HashMap<i32, i32, S>) { } ``` I think this is pedantic. I get that this lint can benefit core libraries like serde, but that's exactly the use case for pedantic lints; a library like serde will [enable clippy_pedantic](https://github.com/serde-rs/json/blob/fd6741f4b0b3fc90a58a6f578e33a9adc6403f3f/src/lib.rs#L304) and take the time to go through everything possible. Similar for libraries doing a libz blitz style checkup before committing to a 1.0 release; it would make sense to run through all the available pedantic lints then. But otherwise, for most codebases and certainly for industrial codebases, the above suggested change just makes the codebase more obtuse for questionable benefit. changelog: Remove implicit_hasher from default set of enabled lints
2 parents 940bbd6 + 5f92fae commit c25f26d

File tree

9 files changed

+31
-23
lines changed

9 files changed

+31
-23
lines changed

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11351135
LintId::of(&types::CAST_POSSIBLE_WRAP),
11361136
LintId::of(&types::CAST_PRECISION_LOSS),
11371137
LintId::of(&types::CAST_SIGN_LOSS),
1138+
LintId::of(&types::IMPLICIT_HASHER),
11381139
LintId::of(&types::INVALID_UPCAST_COMPARISONS),
11391140
LintId::of(&types::LET_UNIT_VALUE),
11401141
LintId::of(&types::LINKEDLIST),
@@ -1383,7 +1384,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13831384
LintId::of(&types::CHAR_LIT_AS_U8),
13841385
LintId::of(&types::FN_TO_NUMERIC_CAST),
13851386
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
1386-
LintId::of(&types::IMPLICIT_HASHER),
13871387
LintId::of(&types::REDUNDANT_ALLOCATION),
13881388
LintId::of(&types::TYPE_COMPLEXITY),
13891389
LintId::of(&types::UNIT_ARG),
@@ -1494,7 +1494,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14941494
LintId::of(&try_err::TRY_ERR),
14951495
LintId::of(&types::FN_TO_NUMERIC_CAST),
14961496
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
1497-
LintId::of(&types::IMPLICIT_HASHER),
14981497
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
14991498
LintId::of(&write::PRINTLN_EMPTY_STRING),
15001499
LintId::of(&write::PRINT_LITERAL),

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ declare_clippy_lint! {
21692169
/// pub fn foo<S: BuildHasher>(map: &mut HashMap<i32, i32, S>) { }
21702170
/// ```
21712171
pub IMPLICIT_HASHER,
2172-
style,
2172+
pedantic,
21732173
"missing generalization over different hashers"
21742174
}
21752175

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
747747
},
748748
Lint {
749749
name: "implicit_hasher",
750-
group: "style",
750+
group: "pedantic",
751751
desc: "missing generalization over different hashers",
752752
deprecation: None,
753753
module: "types",

tests/ui/crashes/ice-3717.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(clippy::implicit_hasher)]
2+
13
use std::collections::HashSet;
24

35
fn main() {}

tests/ui/crashes/ice-3717.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
error: parameter of type `HashSet` should be generalized over different hashers
2-
--> $DIR/ice-3717.rs:5:21
2+
--> $DIR/ice-3717.rs:7:21
33
|
44
LL | pub fn ice_3717(_: &HashSet<usize>) {
55
| ^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::implicit-hasher` implied by `-D warnings`
7+
note: the lint level is defined here
8+
--> $DIR/ice-3717.rs:1:9
9+
|
10+
LL | #![deny(clippy::implicit_hasher)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
812
help: consider adding a type parameter
913
|
1014
LL | pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) {

tests/ui/implicit_hasher.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// aux-build:implicit_hasher_macros.rs
2+
#![deny(clippy::implicit_hasher)]
23
#![allow(unused)]
34

45
#[macro_use]

tests/ui/implicit_hasher.stderr

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
error: impl for `HashMap` should be generalized over different hashers
2-
--> $DIR/implicit_hasher.rs:15:35
2+
--> $DIR/implicit_hasher.rs:16:35
33
|
44
LL | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
55
| ^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::implicit-hasher` implied by `-D warnings`
7+
note: the lint level is defined here
8+
--> $DIR/implicit_hasher.rs:2:9
9+
|
10+
LL | #![deny(clippy::implicit_hasher)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
812
help: consider adding a type parameter
913
|
1014
LL | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V, S> {
@@ -15,7 +19,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
1519
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1620

1721
error: impl for `HashMap` should be generalized over different hashers
18-
--> $DIR/implicit_hasher.rs:24:36
22+
--> $DIR/implicit_hasher.rs:25:36
1923
|
2024
LL | impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
2125
| ^^^^^^^^^^^^^
@@ -30,7 +34,7 @@ LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Defa
3034
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3135

3236
error: impl for `HashMap` should be generalized over different hashers
33-
--> $DIR/implicit_hasher.rs:29:19
37+
--> $DIR/implicit_hasher.rs:30:19
3438
|
3539
LL | impl Foo<i16> for HashMap<String, String> {
3640
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -45,7 +49,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
4549
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4650

4751
error: impl for `HashSet` should be generalized over different hashers
48-
--> $DIR/implicit_hasher.rs:46:32
52+
--> $DIR/implicit_hasher.rs:47:32
4953
|
5054
LL | impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
5155
| ^^^^^^^^^^
@@ -60,7 +64,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
6064
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6165

6266
error: impl for `HashSet` should be generalized over different hashers
63-
--> $DIR/implicit_hasher.rs:51:19
67+
--> $DIR/implicit_hasher.rs:52:19
6468
|
6569
LL | impl Foo<i16> for HashSet<String> {
6670
| ^^^^^^^^^^^^^^^
@@ -75,7 +79,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
7579
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7680

7781
error: parameter of type `HashMap` should be generalized over different hashers
78-
--> $DIR/implicit_hasher.rs:68:23
82+
--> $DIR/implicit_hasher.rs:69:23
7983
|
8084
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
8185
| ^^^^^^^^^^^^^^^^^
@@ -86,7 +90,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _s
8690
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
8791

8892
error: parameter of type `HashSet` should be generalized over different hashers
89-
--> $DIR/implicit_hasher.rs:68:53
93+
--> $DIR/implicit_hasher.rs:69:53
9094
|
9195
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
9296
| ^^^^^^^^^^^^
@@ -97,7 +101,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set:
97101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
98102

99103
error: impl for `HashMap` should be generalized over different hashers
100-
--> $DIR/implicit_hasher.rs:72:43
104+
--> $DIR/implicit_hasher.rs:73:43
101105
|
102106
LL | impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
103107
| ^^^^^^^^^^^^^
@@ -116,7 +120,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10,
116120
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117121

118122
error: parameter of type `HashMap` should be generalized over different hashers
119-
--> $DIR/implicit_hasher.rs:80:33
123+
--> $DIR/implicit_hasher.rs:81:33
120124
|
121125
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
122126
| ^^^^^^^^^^^^^^^^^
@@ -131,7 +135,7 @@ LL | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i
131135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
132136

133137
error: parameter of type `HashSet` should be generalized over different hashers
134-
--> $DIR/implicit_hasher.rs:80:63
138+
--> $DIR/implicit_hasher.rs:81:63
135139
|
136140
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
137141
| ^^^^^^^^^^^^

tests/ui/mut_key.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(clippy::implicit_hasher)]
2-
31
use std::collections::{HashMap, HashSet};
42
use std::hash::{Hash, Hasher};
53
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};

tests/ui/mut_key.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: mutable key type
2-
--> $DIR/mut_key.rs:29:32
2+
--> $DIR/mut_key.rs:27:32
33
|
44
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[deny(clippy::mutable_key_type)]` on by default
88

99
error: mutable key type
10-
--> $DIR/mut_key.rs:29:72
10+
--> $DIR/mut_key.rs:27:72
1111
|
1212
LL | fn should_not_take_this_arg(m: &mut HashMap<Key, usize>, _n: usize) -> HashSet<Key> {
1313
| ^^^^^^^^^^^^
1414

1515
error: mutable key type
16-
--> $DIR/mut_key.rs:30:5
16+
--> $DIR/mut_key.rs:28:5
1717
|
1818
LL | let _other: HashMap<Key, bool> = HashMap::new();
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
error: mutable key type
22-
--> $DIR/mut_key.rs:49:22
22+
--> $DIR/mut_key.rs:47:22
2323
|
2424
LL | fn tuples_bad<U>(_m: &mut HashMap<(Key, U), bool>) {}
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)