Skip to content

Commit

Permalink
Auto merge of #4772 - HMPerson1:tastier_ice_cream, r=flip1995
Browse files Browse the repository at this point in the history
Use correct TypeckTables when hashing bodies

Fixes #4760

changelog: Fix ICE while hashing block expressions #4760

r? @phansch
  • Loading branch information
bors committed Nov 6, 2019
2 parents 865f5c7 + e3d6069 commit 0be213b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 13 additions & 9 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
CaptureClause::CaptureByRef => 1,
}
.hash(&mut self.s);
// closures inherit TypeckTables
self.hash_expr(&self.cx.tcx.hir().body(eid).value);
},
ExprKind::Field(ref e, ref f) => {
Expand Down Expand Up @@ -490,10 +491,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
},
ExprKind::Repeat(ref e, ref l_id) => {
self.hash_expr(e);
let full_table = self.tables;
self.tables = self.cx.tcx.body_tables(l_id.body);
self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
self.tables = full_table;
self.hash_body(l_id.body);
},
ExprKind::Ret(ref e) => {
if let Some(ref e) = *e {
Expand Down Expand Up @@ -609,7 +607,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
},
TyKind::Array(ty, anon_const) => {
self.hash_ty(ty);
self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value);
self.hash_body(anon_const.body);
},
TyKind::Ptr(mut_ty) => {
self.hash_ty(&mut_ty.ty);
Expand Down Expand Up @@ -660,19 +658,25 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
match arg {
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
GenericArg::Type(ref ty) => self.hash_ty(&ty),
GenericArg::Const(ref ca) => {
self.hash_expr(&self.cx.tcx.hir().body(ca.value.body).value);
},
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
}
}
},
TyKind::TraitObject(_, lifetime) => {
self.hash_lifetime(lifetime);
},
TyKind::Typeof(anon_const) => {
self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value);
self.hash_body(anon_const.body);
},
TyKind::Err | TyKind::Infer | TyKind::Never => {},
}
}

pub fn hash_body(&mut self, body_id: BodyId) {
// swap out TypeckTables when hashing a body
let old_tables = self.tables;
self.tables = self.cx.tcx.body_tables(body_id);
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
self.tables = old_tables;
}
}
10 changes: 10 additions & 0 deletions tests/ui/crashes/ice-4760.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// run-pass
const COUNT: usize = 2;
struct Thing;
trait Dummy {}

const _: () = {
impl Dummy for Thing where [i32; COUNT]: Sized {}
};

fn main() {}

0 comments on commit 0be213b

Please sign in to comment.