Skip to content

Commit 3311b36

Browse files
committed
Auto merge of #7761 - giraffate:fix_ice_in_inplicit_hasher, r=Manishearth
Fix ICE in `implicit_hasher` close #7712 changelog: Fix ICE in [`implicit_hasher`]
2 parents 63b04f7 + 72f0180 commit 3311b36

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

clippy_lints/src/implicit_hasher.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,20 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
167167
continue;
168168
}
169169
let generics_suggestion_span = generics.span.substitute_dummy({
170-
let pos = snippet_opt(cx, item.span.until(body.params[0].pat.span))
171-
.and_then(|snip| {
172-
let i = snip.find("fn")?;
173-
Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32))
174-
})
175-
.expect("failed to create span for type parameters");
170+
let pos = snippet_opt(
171+
cx,
172+
Span::new(
173+
item.span.lo(),
174+
body.params[0].pat.span.lo(),
175+
item.span.ctxt(),
176+
item.span.parent(),
177+
),
178+
)
179+
.and_then(|snip| {
180+
let i = snip.find("fn")?;
181+
Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32))
182+
})
183+
.expect("failed to create span for type parameters");
176184
Span::new(pos, pos, item.span.ctxt(), item.span.parent())
177185
});
178186

tests/ui/implicit_hasher.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// edition:2018
12
// aux-build:implicit_hasher_macros.rs
23
#![deny(clippy::implicit_hasher)]
34
#![allow(unused)]
@@ -96,4 +97,7 @@ __implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::
9697
// #4260
9798
implicit_hasher_fn!();
9899

100+
// #7712
101+
pub async fn election_vote(_data: HashMap<i32, i32>) {}
102+
99103
fn main() {}

tests/ui/implicit_hasher.stderr

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: impl for `HashMap` should be generalized over different hashers
2-
--> $DIR/implicit_hasher.rs:16:35
2+
--> $DIR/implicit_hasher.rs:17:35
33
|
44
LL | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
55
| ^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/implicit_hasher.rs:2:9
8+
--> $DIR/implicit_hasher.rs:3:9
99
|
1010
LL | #![deny(clippy::implicit_hasher)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -19,7 +19,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
1919
| ~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020

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

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

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

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

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

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

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

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

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

152-
error: aborting due to 10 previous errors
152+
error: parameter of type `HashMap` should be generalized over different hashers
153+
--> $DIR/implicit_hasher.rs:101:35
154+
|
155+
LL | pub async fn election_vote(_data: HashMap<i32, i32>) {}
156+
| ^^^^^^^^^^^^^^^^^
157+
|
158+
help: consider adding a type parameter
159+
|
160+
LL | pub async fn election_vote<S: ::std::hash::BuildHasher>(_data: HashMap<i32, i32, S>) {}
161+
| +++++++++++++++++++++++++++++ ~~~~~~~~~~~~~~~~~~~~
162+
163+
error: aborting due to 11 previous errors
153164

0 commit comments

Comments
 (0)