From f204b7ec767b6bcd3b4e0e5893e2108f2d13e031 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 16 Feb 2019 22:40:44 +0100 Subject: [PATCH 1/2] Fix ICE #3717 Restore the old `TypeckTables` in visit_body after walking the body --- clippy_lints/src/types.rs | 2 ++ 1 file changed, 2 insertions(+) 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) { From 9148fc274ad17dd8911aeff5429ce4ee222d8b35 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 16 Feb 2019 22:41:06 +0100 Subject: [PATCH 2/2] Add test for ICE #3717 fix --- tests/ui/ice-3717.rs | 8 ++++++++ tests/ui/ice-3717.stderr | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ui/ice-3717.rs create mode 100644 tests/ui/ice-3717.stderr 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) { + let _ = [0u8; 0]; + let _: HashSet = 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) { + | ^^^^^^^^^^^^^^ + | + = note: `-D clippy::implicit-hasher` implied by `-D warnings` +help: consider adding a type parameter + | +LL | pub fn ice_3717(_: &HashSet) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ +help: ...and use generic constructor + | +LL | let _: HashSet = HashSet::default(); + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error +