Skip to content

Commit 2a30d18

Browse files
committed
Cleanup
1 parent 35eefc1 commit 2a30d18

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,6 +2243,9 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
22432243

22442244
let reachable_set = tcx.reachable_set(());
22452245
par_for_each_in(tcx.mir_keys(()), |&&def_id| {
2246+
if tcx.is_trivial_const(def_id).is_some() {
2247+
return;
2248+
}
22462249
let (encode_const, encode_opt) = should_encode_mir(tcx, reachable_set, def_id);
22472250

22482251
if encode_const {

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use rustc_hir::def::{CtorKind, DefKind};
2323
use rustc_hir::def_id::LocalDefId;
2424
use rustc_index::IndexVec;
2525
use rustc_middle::mir::{
26-
AnalysisPhase, Body, CallSource, ClearCrossCrate, ConstOperand, ConstQualifs, LocalDecl,
27-
MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue, START_BLOCK,
28-
SourceInfo, Statement, StatementKind, TerminatorKind,
26+
AnalysisPhase, Body, CallSource, ClearCrossCrate, ConstOperand, ConstQualifs, ConstValue,
27+
LocalDecl, MirPhase, Operand, Place, ProjectionElem, Promoted, RuntimePhase, Rvalue,
28+
START_BLOCK, SourceInfo, Statement, StatementKind, TerminatorKind,
2929
};
3030
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
3131
use rustc_middle::util::Providers;
@@ -382,10 +382,13 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: LocalDefId) -> ConstQualifs {
382382
validator.qualifs_in_return_place()
383383
}
384384

385-
use rustc_middle::mir::ConstValue;
386385
fn is_trivial_const<'tcx>(body: &Body<'tcx>) -> Option<(ConstValue, Ty<'tcx>)> {
387386
use rustc_middle::mir::RETURN_PLACE;
388387

388+
if body.has_opaque_types() {
389+
return None;
390+
}
391+
389392
if body.basic_blocks.len() != 1 {
390393
return None;
391394
}
@@ -452,9 +455,10 @@ fn mir_promoted(
452455
tcx: TyCtxt<'_>,
453456
def: LocalDefId,
454457
) -> (&Steal<Body<'_>>, &Steal<IndexVec<Promoted, Body<'_>>>) {
455-
if tcx.is_trivial_const(def).is_some() {
456-
panic!("Tried to get MIR of a trivial const");
457-
}
458+
debug_assert!(
459+
tcx.is_trivial_const(def).is_some(),
460+
"Tried to get mir_promoted of a trivial const"
461+
);
458462

459463
// Ensure that we compute the `mir_const_qualif` for constants at
460464
// this point, before we steal the mir-const result.
@@ -483,7 +487,7 @@ fn mir_promoted(
483487
tcx.ensure_done().coroutine_by_move_body_def_id(def);
484488
}
485489

486-
// the `is_trivial_const` uses mir_built, so make sure it is run.
490+
// the `is_trivial_const` query uses mir_built, so make sure it is run.
487491
tcx.ensure_done().is_trivial_const(def);
488492

489493
let mut body = tcx.mir_built(def).steal();
@@ -513,9 +517,10 @@ fn mir_promoted(
513517

514518
/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
515519
fn mir_for_ctfe(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &Body<'_> {
516-
if tcx.is_trivial_const(def_id).is_some() {
517-
panic!("Tried to get mir_for_ctfe of a trivial const");
518-
}
520+
debug_assert!(
521+
tcx.is_trivial_const(def_id).is_none(),
522+
"Tried to get mir_for_ctfe of a trivial const"
523+
);
519524
tcx.arena.alloc(inner_mir_for_ctfe(tcx, def_id))
520525
}
521526

0 commit comments

Comments
 (0)