about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2019-09-08 21:19:47 +0200
committerIgor Matuszewski <Xanewok@gmail.com>2019-09-13 15:31:50 +0200
commitb456c820ffe6f19d133f196d3e935071f326094e (patch)
tree503e5f4e4942580f0ce2d48feec9cf37a6c231d2
parentab73b325b0e1288656f69ee24acb822fe91bc6a0 (diff)
downloadrust-b456c820ffe6f19d133f196d3e935071f326094e.tar.gz
rust-b456c820ffe6f19d133f196d3e935071f326094e.zip
Always validate HIR ID for TypeckTables
Performance shouldn't be impacted (see [1] for a perf run) and this
should allow us to catch more bugs, e.g. [2] and [3].

[1]: https://github.com/rust-lang/rust/pull/64262
[2]: https://github.com/rust-lang/rust/pull/64250
[3]: https://github.com/rust-lang/rust/issues/57298
-rw-r--r--src/librustc/ty/context.rs38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 8e8472a5aac..7366037c5eb 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -205,26 +205,24 @@ pub struct LocalTableInContext<'a, V> {
 fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
                                      hir_id: hir::HirId,
                                      mut_access: bool) {
-    if cfg!(debug_assertions) {
-        if let Some(local_id_root) = local_id_root {
-            if hir_id.owner != local_id_root.index {
-                ty::tls::with(|tcx| {
-                    bug!("node {} with HirId::owner {:?} cannot be placed in \
-                          TypeckTables with local_id_root {:?}",
-                         tcx.hir().node_to_string(hir_id),
-                         DefId::local(hir_id.owner),
-                         local_id_root)
-                });
-            }
-        } else {
-            // We use "Null Object" TypeckTables in some of the analysis passes.
-            // These are just expected to be empty and their `local_id_root` is
-            // `None`. Therefore we cannot verify whether a given `HirId` would
-            // be a valid key for the given table. Instead we make sure that
-            // nobody tries to write to such a Null Object table.
-            if mut_access {
-                bug!("access to invalid TypeckTables")
-            }
+    if let Some(local_id_root) = local_id_root {
+        if hir_id.owner != local_id_root.index {
+            ty::tls::with(|tcx| {
+                bug!("node {} with HirId::owner {:?} cannot be placed in \
+                        TypeckTables with local_id_root {:?}",
+                        tcx.hir().node_to_string(hir_id),
+                        DefId::local(hir_id.owner),
+                        local_id_root)
+            });
+        }
+    } else {
+        // We use "Null Object" TypeckTables in some of the analysis passes.
+        // These are just expected to be empty and their `local_id_root` is
+        // `None`. Therefore we cannot verify whether a given `HirId` would
+        // be a valid key for the given table. Instead we make sure that
+        // nobody tries to write to such a Null Object table.
+        if mut_access {
+            bug!("access to invalid TypeckTables")
         }
     }
 }