Skip to content

Commit b456c82

Browse files
committed
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]: #64262 [2]: #64250 [3]: #57298
1 parent ab73b32 commit b456c82

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/librustc/ty/context.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,24 @@ pub struct LocalTableInContext<'a, V> {
205205
fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
206206
hir_id: hir::HirId,
207207
mut_access: bool) {
208-
if cfg!(debug_assertions) {
209-
if let Some(local_id_root) = local_id_root {
210-
if hir_id.owner != local_id_root.index {
211-
ty::tls::with(|tcx| {
212-
bug!("node {} with HirId::owner {:?} cannot be placed in \
213-
TypeckTables with local_id_root {:?}",
214-
tcx.hir().node_to_string(hir_id),
215-
DefId::local(hir_id.owner),
216-
local_id_root)
217-
});
218-
}
219-
} else {
220-
// We use "Null Object" TypeckTables in some of the analysis passes.
221-
// These are just expected to be empty and their `local_id_root` is
222-
// `None`. Therefore we cannot verify whether a given `HirId` would
223-
// be a valid key for the given table. Instead we make sure that
224-
// nobody tries to write to such a Null Object table.
225-
if mut_access {
226-
bug!("access to invalid TypeckTables")
227-
}
208+
if let Some(local_id_root) = local_id_root {
209+
if hir_id.owner != local_id_root.index {
210+
ty::tls::with(|tcx| {
211+
bug!("node {} with HirId::owner {:?} cannot be placed in \
212+
TypeckTables with local_id_root {:?}",
213+
tcx.hir().node_to_string(hir_id),
214+
DefId::local(hir_id.owner),
215+
local_id_root)
216+
});
217+
}
218+
} else {
219+
// We use "Null Object" TypeckTables in some of the analysis passes.
220+
// These are just expected to be empty and their `local_id_root` is
221+
// `None`. Therefore we cannot verify whether a given `HirId` would
222+
// be a valid key for the given table. Instead we make sure that
223+
// nobody tries to write to such a Null Object table.
224+
if mut_access {
225+
bug!("access to invalid TypeckTables")
228226
}
229227
}
230228
}

0 commit comments

Comments
 (0)