Skip to content

Commit f415379

Browse files
committed
Add proper cfgs for struct HirIdValidator used only with debug assertions
1 parent 2064c19 commit f415379

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

compiler/rustc_interface/src/passes.rs

+5
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,11 @@ pub fn create_global_ctxt<'tcx>(
686686
/// Runs the type-checking, region checking and other miscellaneous analysis
687687
/// passes on the crate.
688688
fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
689+
if tcx.sess.opts.unstable_opts.hir_stats {
690+
rustc_passes::hir_stats::print_hir_stats(tcx);
691+
}
692+
693+
#[cfg(debug_assertions)]
689694
rustc_passes::hir_id_validator::check_crate(tcx);
690695

691696
let sess = tcx.sess;

compiler/rustc_passes/src/hir_id_validator.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
use rustc_data_structures::sync::Lock;
22
use rustc_hir as hir;
33
use rustc_hir::def_id::LocalDefId;
4-
use rustc_hir::intravisit;
5-
use rustc_hir::{HirId, ItemLocalId};
4+
use rustc_hir::{intravisit, HirId, ItemLocalId};
65
use rustc_index::bit_set::GrowableBitSet;
76
use rustc_middle::hir::nested_filter;
87
use rustc_middle::ty::TyCtxt;
98

109
pub fn check_crate(tcx: TyCtxt<'_>) {
11-
if tcx.sess.opts.unstable_opts.hir_stats {
12-
crate::hir_stats::print_hir_stats(tcx);
13-
}
14-
15-
#[cfg(debug_assertions)]
16-
{
17-
let errors = Lock::new(Vec::new());
10+
let errors = Lock::new(Vec::new());
1811

19-
tcx.hir().par_for_each_module(|module_id| {
20-
let mut v = HirIdValidator {
21-
tcx,
22-
owner: None,
23-
hir_ids_seen: Default::default(),
24-
errors: &errors,
25-
};
12+
tcx.hir().par_for_each_module(|module_id| {
13+
let mut v =
14+
HirIdValidator { tcx, owner: None, hir_ids_seen: Default::default(), errors: &errors };
2615

27-
tcx.hir().visit_item_likes_in_module(module_id, &mut v);
28-
});
16+
tcx.hir().visit_item_likes_in_module(module_id, &mut v);
17+
});
2918

30-
let errors = errors.into_inner();
19+
let errors = errors.into_inner();
3120

32-
if !errors.is_empty() {
33-
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
34-
tcx.dcx().delayed_bug(message);
35-
}
21+
if !errors.is_empty() {
22+
let message = errors.iter().fold(String::new(), |s1, s2| s1 + "\n" + s2);
23+
tcx.dcx().delayed_bug(message);
3624
}
3725
}
3826

@@ -90,7 +78,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
9078
self.error(|| {
9179
format!(
9280
"ItemLocalIds not assigned densely in {pretty_owner}. \
93-
Max ItemLocalId = {max}, missing IDs = {missing_items:#?}; seen IDs = {seen_items:#?}"
81+
Max ItemLocalId = {max}, missing IDs = {missing_items:#?}; seen IDs = {seen_items:#?}"
9482
)
9583
});
9684
}

compiler/rustc_passes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod debugger_visualizer;
2828
mod diagnostic_items;
2929
pub mod entry;
3030
mod errors;
31+
#[cfg(debug_assertions)]
3132
pub mod hir_id_validator;
3233
pub mod hir_stats;
3334
mod lang_items;

0 commit comments

Comments
 (0)