Skip to content

Commit

Permalink
Fic ICE in implicit_hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Oct 4, 2021
1 parent 63b04f7 commit 34a5b64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
20 changes: 14 additions & 6 deletions clippy_lints/src/implicit_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,20 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
continue;
}
let generics_suggestion_span = generics.span.substitute_dummy({
let pos = snippet_opt(cx, item.span.until(body.params[0].pat.span))
.and_then(|snip| {
let i = snip.find("fn")?;
Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32))
})
.expect("failed to create span for type parameters");
let pos = snippet_opt(
cx,
Span::new(
item.span.lo(),
body.params[0].pat.span.lo(),
item.span.ctxt(),
item.span.parent(),
),
)
.and_then(|snip| {
let i = snip.find("fn")?;
Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32))
})
.expect("failed to create span for type parameters");
Span::new(pos, pos, item.span.ctxt(), item.span.parent())
});

Expand Down
4 changes: 4 additions & 0 deletions tests/ui/implicit_hasher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// edition:2018
// aux-build:implicit_hasher_macros.rs
#![deny(clippy::implicit_hasher)]
#![allow(unused)]
Expand Down Expand Up @@ -96,4 +97,7 @@ __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::
// #4260
implicit_hasher_fn!();

// #7712
pub async fn election_vote(_data: HashMap<i32, i32>) {}

fn main() {}
35 changes: 23 additions & 12 deletions tests/ui/implicit_hasher.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: impl for `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:16:35
--> $DIR/implicit_hasher.rs:17:35
|
LL | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
| ^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/implicit_hasher.rs:2:9
--> $DIR/implicit_hasher.rs:3:9
|
LL | #![deny(clippy::implicit_hasher)]
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -19,7 +19,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: impl for `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:25:36
--> $DIR/implicit_hasher.rs:26:36
|
LL | impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
| ^^^^^^^^^^^^^
Expand All @@ -34,7 +34,7 @@ LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Defa
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: impl for `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:30:19
--> $DIR/implicit_hasher.rs:31:19
|
LL | impl Foo<i16> for HashMap<String, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -49,7 +49,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: impl for `HashSet` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:47:32
--> $DIR/implicit_hasher.rs:48:32
|
LL | impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
| ^^^^^^^^^^
Expand All @@ -64,7 +64,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: impl for `HashSet` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:52:19
--> $DIR/implicit_hasher.rs:53:19
|
LL | impl Foo<i16> for HashSet<String> {
| ^^^^^^^^^^^^^^^
Expand All @@ -79,7 +79,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: parameter of type `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:69:23
--> $DIR/implicit_hasher.rs:70:23
|
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
| ^^^^^^^^^^^^^^^^^
Expand All @@ -90,7 +90,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _s
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~

error: parameter of type `HashSet` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:69:53
--> $DIR/implicit_hasher.rs:70:53
|
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
| ^^^^^^^^^^^^
Expand All @@ -101,7 +101,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set:
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~

error: impl for `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:73:43
--> $DIR/implicit_hasher.rs:74:43
|
LL | impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
| ^^^^^^^^^^^^^
Expand All @@ -120,7 +120,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10,
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: parameter of type `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:81:33
--> $DIR/implicit_hasher.rs:82:33
|
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
| ^^^^^^^^^^^^^^^^^
Expand All @@ -135,7 +135,7 @@ LL | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~

error: parameter of type `HashSet` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:81:63
--> $DIR/implicit_hasher.rs:82:63
|
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
| ^^^^^^^^^^^^
Expand All @@ -149,5 +149,16 @@ help: consider adding a type parameter
LL | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {}
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~

error: aborting due to 10 previous errors
error: parameter of type `HashMap` should be generalized over different hashers
--> $DIR/implicit_hasher.rs:101:35
|
LL | pub async fn election_vote(_data: HashMap<i32, i32>) {}
| ^^^^^^^^^^^^^^^^^
|
help: consider adding a type parameter
|
LL | pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {}
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~

error: aborting due to 11 previous errors

0 comments on commit 34a5b64

Please sign in to comment.