about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-02-17 07:03:15 +0000
committerbors <bors@rust-lang.org>2019-02-17 07:03:15 +0000
commita71acac1da7eaf667ab90a1d65d10e5cc4b80191 (patch)
tree85298b80606557ecfdc05b1682a89b07aca32d33
parentf08e268d95cec9d91030aaf747615bc574dcbfe5 (diff)
parent9148fc274ad17dd8911aeff5429ce4ee222d8b35 (diff)
downloadrust-a71acac1da7eaf667ab90a1d65d10e5cc4b80191.tar.gz
rust-a71acac1da7eaf667ab90a1d65d10e5cc4b80191.zip
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`?
-rw-r--r--clippy_lints/src/types.rs2
-rw-r--r--tests/ui/ice-3717.rs8
-rw-r--r--tests/ui/ice-3717.stderr18
3 files changed, 28 insertions, 0 deletions
diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs
index 79e9f4f27d2..227b10cd29a 100644
--- a/clippy_lints/src/types.rs
+++ b/clippy_lints/src/types.rs
@@ -2239,8 +2239,10 @@ impl<'a, 'b, 'tcx: 'a + 'b> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
 
 impl<'a, 'b, 'tcx: 'a + 'b> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
     fn visit_body(&mut self, body: &'tcx Body) {
+        let prev_body = self.body;
         self.body = self.cx.tcx.body_tables(body.id());
         walk_body(self, body);
+        self.body = prev_body;
     }
 
     fn visit_expr(&mut self, e: &'tcx Expr) {
diff --git a/tests/ui/ice-3717.rs b/tests/ui/ice-3717.rs
new file mode 100644
index 00000000000..21c48f4749c
--- /dev/null
+++ b/tests/ui/ice-3717.rs
@@ -0,0 +1,8 @@
+use std::collections::HashSet;
+
+fn main() {}
+
+pub fn ice_3717(_: &HashSet<usize>) {
+    let _ = [0u8; 0];
+    let _: HashSet<usize> = HashSet::new();
+}
diff --git a/tests/ui/ice-3717.stderr b/tests/ui/ice-3717.stderr
new file mode 100644
index 00000000000..08c53c399c2
--- /dev/null
+++ b/tests/ui/ice-3717.stderr
@@ -0,0 +1,18 @@
+error: parameter of type `HashSet` should be generalized over different hashers
+  --> $DIR/ice-3717.rs:5:21
+   |
+LL | pub fn ice_3717(_: &HashSet<usize>) {
+   |                     ^^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::implicit-hasher` implied by `-D warnings`
+help: consider adding a type parameter
+   |
+LL | pub fn ice_3717<S: ::std::hash::BuildHasher + Default>(_: &HashSet<usize, S>) {
+   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^
+help: ...and use generic constructor
+   |
+LL |     let _: HashSet<usize> = HashSet::default();
+   |                             ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+