Skip to content

Commit a71acac

Browse files
committed
Auto merge of #3775 - flip1995:ice-3717, r=phansch
Fix ICE #3717 in lint implicit_hasher Fixes #3717 This fixes the ICE. We lose some information in a very specific case though. But less information if better than an ICE. For an example see the test file. Does anyone know, if there's another way to get the `ty::Ty` of a `hir::Expr`?
2 parents f08e268 + 9148fc2 commit a71acac

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

clippy_lints/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,8 +2239,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
22392239

22402240
impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
22412241
fn visit_body(&mut self, body: &'tcx Body) {
2242+
let prev_body = self.body;
22422243
self.body = self.cx.tcx.body_tables(body.id());
22432244
walk_body(self, body);
2245+
self.body = prev_body;
22442246
}
22452247

22462248
fn visit_expr(&mut self, e: &'tcx Expr) {

tests/ui/ice-3717.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::collections::HashSet;
2+
3+
fn main() {}
4+
5+
pub fn ice_3717(_: &HashSet<usize>) {
6+
let _ = [0u8; 0];
7+
let _: HashSet<usize> = HashSet::new();
8+
}

tests/ui/ice-3717.stderr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: parameter of type `HashSet` should be generalized over different hashers
2+
--> $DIR/ice-3717.rs:5:21
3+
|
4+
LL | pub fn ice_3717(_: &HashSet<usize>) {
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::implicit-hasher` implied by `-D warnings`
8+
help: consider adding a type parameter
9+
|
10+
LL | pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
12+
help: ...and use generic constructor
13+
|
14+
LL | let _: HashSet<usize> = HashSet::default();
15+
| ^^^^^^^^^^^^^^^^^^
16+
17+
error: aborting due to previous error
18+

0 commit comments

Comments
 (0)