Skip to content

Commit

Permalink
Fix const qualification when executed after promotion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmiasko committed Oct 19, 2021
1 parent 1af55d1 commit 7581bae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ where

// Check the qualifs of the value of `const` items.
if let Some(ct) = constant.literal.const_for_ty() {
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted }) = ct.val {
assert!(promoted.is_none());
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs_: _, promoted: None }) =
ct.val
{
// Don't peek inside trait associated constants.
if cx.tcx.trait_of_item(def.did).is_none() {
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/precise-drop-with-promoted.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Regression test for issue #89938.
// check-pass
// compile-flags: --crate-type=lib
#![feature(const_precise_live_drops)]

pub const fn f() {
let _: Option<String> = None;
let _: &'static Option<String> = &None;
}

0 comments on commit 7581bae

Please sign in to comment.