Skip to content

Commit 7581bae

Browse files
committed
Fix const qualification when executed after promotion
The const qualification was so far performed before the promotion and the implementation assumed that it will never encounter a promoted. With `const_precise_live_drops` feature, checking for live drops is delayed until after drop elaboration, which in turn runs after promotion. so the assumption is no longer true. When evaluating `NeedsNonConstDrop` it is now possible to encounter promoteds. Use type base qualification for the promoted. It is a sound approximation in general, and in the specific case of promoteds and `NeedsNonConstDrop` it is precise.
1 parent 1af55d1 commit 7581bae

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ where
309309

310310
// Check the qualifs of the value of `const` items.
311311
if let Some(ct) = constant.literal.const_for_ty() {
312-
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val {
313-
assert!(promoted.is_none());
312+
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: None }) =
313+
ct.val
314+
{
314315
// Don't peek inside trait associated constants.
315316
if cx.tcx.trait_of_item(def.did).is_none() {
316317
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Regression test for issue #89938.
2+
// check-pass
3+
// compile-flags: --crate-type=lib
4+
#![feature(const_precise_live_drops)]
5+
6+
pub const fn f() {
7+
let _: Option<String> = None;
8+
let _: &'static Option<String> = &None;
9+
}

0 commit comments

Comments
 (0)