Skip to content

Commit 28ef141

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 53de8a7 commit 28ef141

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

0 commit comments

Comments
 (0)