Skip to content

Commit 0be213b

Browse files
committed
Auto merge of #4772 - HMPerson1:tastier_ice_cream, r=flip1995
Use correct TypeckTables when hashing bodies Fixes #4760 changelog: Fix ICE while hashing block expressions #4760 r? @phansch
2 parents 865f5c7 + e3d6069 commit 0be213b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

clippy_lints/src/utils/hir_utils.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
451451
CaptureClause::CaptureByRef => 1,
452452
}
453453
.hash(&mut self.s);
454+
// closures inherit TypeckTables
454455
self.hash_expr(&self.cx.tcx.hir().body(eid).value);
455456
},
456457
ExprKind::Field(ref e, ref f) => {
@@ -490,10 +491,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
490491
},
491492
ExprKind::Repeat(ref e, ref l_id) => {
492493
self.hash_expr(e);
493-
let full_table = self.tables;
494-
self.tables = self.cx.tcx.body_tables(l_id.body);
495-
self.hash_expr(&self.cx.tcx.hir().body(l_id.body).value);
496-
self.tables = full_table;
494+
self.hash_body(l_id.body);
497495
},
498496
ExprKind::Ret(ref e) => {
499497
if let Some(ref e) = *e {
@@ -609,7 +607,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
609607
},
610608
TyKind::Array(ty, anon_const) => {
611609
self.hash_ty(ty);
612-
self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value);
610+
self.hash_body(anon_const.body);
613611
},
614612
TyKind::Ptr(mut_ty) => {
615613
self.hash_ty(&mut_ty.ty);
@@ -660,19 +658,25 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
660658
match arg {
661659
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
662660
GenericArg::Type(ref ty) => self.hash_ty(&ty),
663-
GenericArg::Const(ref ca) => {
664-
self.hash_expr(&self.cx.tcx.hir().body(ca.value.body).value);
665-
},
661+
GenericArg::Const(ref ca) => self.hash_body(ca.value.body),
666662
}
667663
}
668664
},
669665
TyKind::TraitObject(_, lifetime) => {
670666
self.hash_lifetime(lifetime);
671667
},
672668
TyKind::Typeof(anon_const) => {
673-
self.hash_expr(&self.cx.tcx.hir().body(anon_const.body).value);
669+
self.hash_body(anon_const.body);
674670
},
675671
TyKind::Err | TyKind::Infer | TyKind::Never => {},
676672
}
677673
}
674+
675+
pub fn hash_body(&mut self, body_id: BodyId) {
676+
// swap out TypeckTables when hashing a body
677+
let old_tables = self.tables;
678+
self.tables = self.cx.tcx.body_tables(body_id);
679+
self.hash_expr(&self.cx.tcx.hir().body(body_id).value);
680+
self.tables = old_tables;
681+
}
678682
}

tests/ui/crashes/ice-4760.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-pass
2+
const COUNT: usize = 2;
3+
struct Thing;
4+
trait Dummy {}
5+
6+
const _: () = {
7+
impl Dummy for Thing where [i32; COUNT]: Sized {}
8+
};
9+
10+
fn main() {}

0 commit comments

Comments
 (0)