about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHMPerson1 <hmperson1@gmail.com>2019-11-04 20:03:03 -0500
committerHMPerson1 <hmperson1@gmail.com>2019-11-04 20:03:03 -0500
commite3d6069e1845827a1f507882b407122db4418aa4 (patch)
tree6678ccdbf2be8dee9f4cf4d140df18cddbb9f262
parent000c3ff278852788bc88ce6a911050d02d39af93 (diff)
downloadrust-e3d6069e1845827a1f507882b407122db4418aa4.tar.gz
rust-e3d6069e1845827a1f507882b407122db4418aa4.zip
Use correct TypeckTables when hashing bodies
-rw-r--r--clippy_lints/src/utils/hir_utils.rs22
-rw-r--r--tests/ui/crashes/ice-4760.rs10
2 files changed, 23 insertions, 9 deletions
diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs
index d8b20a5df61..5602e76322d 100644
--- a/clippy_lints/src/utils/hir_utils.rs
+++ b/clippy_lints/src/utils/hir_utils.rs
@@ -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) => {
@@ -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 {
@@ -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);
@@ -660,9 +658,7 @@ 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),
                     }
                 }
             },
@@ -670,9 +666,17 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
                 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;
+    }
 }
diff --git a/tests/ui/crashes/ice-4760.rs b/tests/ui/crashes/ice-4760.rs
new file mode 100644
index 00000000000..ead67d5ed1b
--- /dev/null
+++ b/tests/ui/crashes/ice-4760.rs
@@ -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() {}