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`?
This commit is contained in:
bors 2019-02-17 07:03:15 +00:00
commit a71acac1da
3 changed files with 28 additions and 0 deletions

View File

@ -2239,8 +2239,10 @@ fn new(cx: &'a LateContext<'a, 'tcx>, target: &'b ImplicitHasherType<'tcx>) -> S
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) {

8
tests/ui/ice-3717.rs Normal file
View File

@ -0,0 +1,8 @@
use std::collections::HashSet;
fn main() {}
pub fn ice_3717(_: &HashSet<usize>) {
let _ = [0u8; 0];
let _: HashSet<usize> = HashSet::new();
}

18
tests/ui/ice-3717.stderr Normal file
View File

@ -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