Skip to content

Commit 2dc6689

Browse files
committed
add comments explaining where post-mono const eval errors abort compilation
1 parent 39db6a0 commit 2dc6689

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/rustc_monomorphize/src/collector.rs

+4
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
821821
fn visit_constant(&mut self, constant: &mir::ConstOperand<'tcx>, location: Location) {
822822
let const_ = self.monomorphize(constant.const_);
823823
let param_env = ty::ParamEnv::reveal_all();
824+
// Evaluate the constant. This makes const eval failure a collection-time error (rather than
825+
// a codegen-time error). rustc stops after collection if there was an error, so this
826+
// ensures codegen never has to worry about failing consts.
827+
// (codegen relies on this and ICEs will happen if this is violated.)
824828
let val = match const_.eval(self.tcx, param_env, None) {
825829
Ok(v) => v,
826830
Err(ErrorHandled::Reported(..)) => return,

compiler/rustc_monomorphize/src/partitioning.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,9 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
11141114

11151115
let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_mode);
11161116

1117+
// If there was an error during collection (e.g. from one of the constants we evaluated),
1118+
// then we stop here. This way codegen does not have to worry about failing constants.
1119+
// (codegen relies on this and ICEs will happen if this is violated.)
11171120
tcx.dcx().abort_if_errors();
11181121

11191122
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {

0 commit comments

Comments
 (0)