summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_const_eval/src/transform/promote_consts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_const_eval/src/transform/promote_consts.rs')
-rw-r--r--compiler/rustc_const_eval/src/transform/promote_consts.rs13
1 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs
index f3ae16da4..6777fae74 100644
--- a/compiler/rustc_const_eval/src/transform/promote_consts.rs
+++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs
@@ -45,11 +45,10 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
// There's not really any point in promoting errorful MIR.
//
// This does not include MIR that failed const-checking, which we still try to promote.
- if body.return_ty().references_error() {
- tcx.sess.delay_span_bug(body.span, "PromoteTemps: MIR had errors");
+ if let Err(_) = body.return_ty().error_reported() {
+ debug!("PromoteTemps: MIR had errors");
return;
}
-
if body.source.promoted.is_some() {
return;
}
@@ -319,14 +318,14 @@ impl<'tcx> Validator<'_, 'tcx> {
match elem {
ProjectionElem::Deref => {
let mut promotable = false;
+ // When a static is used by-value, that gets desugared to `*STATIC_ADDR`,
+ // and we need to be able to promote this. So check if this deref matches
+ // that specific pattern.
+
// We need to make sure this is a `Deref` of a local with no further projections.
// Discussion can be found at
// https://github.com/rust-lang/rust/pull/74945#discussion_r463063247
if let Some(local) = place_base.as_local() {
- // This is a special treatment for cases like *&STATIC where STATIC is a
- // global static variable.
- // This pattern is generated only when global static variables are directly
- // accessed and is qualified for promotion safely.
if let TempState::Defined { location, .. } = self.temps[local] {
let def_stmt = self.body[location.block]
.statements