@@ -46,6 +46,9 @@ pub trait Qualif {
46
46
/// Whether this `Qualif` is cleared when a local is moved from.
47
47
const IS_CLEARED_ON_MOVE : bool = false ;
48
48
49
+ /// Whether this `Qualif` might be evaluated after the promotion and can encounter a promoted.
50
+ const ALLOW_PROMOTED : bool = false ;
51
+
49
52
/// Extracts the field of `ConstQualifs` that corresponds to this `Qualif`.
50
53
fn in_qualifs ( qualifs : & ConstQualifs ) -> bool ;
51
54
@@ -129,6 +132,7 @@ pub struct NeedsNonConstDrop;
129
132
impl Qualif for NeedsNonConstDrop {
130
133
const ANALYSIS_NAME : & ' static str = "flow_needs_nonconst_drop" ;
131
134
const IS_CLEARED_ON_MOVE : bool = true ;
135
+ const ALLOW_PROMOTED : bool = true ;
132
136
133
137
fn in_qualifs ( qualifs : & ConstQualifs ) -> bool {
134
138
qualifs. needs_non_const_drop
@@ -309,11 +313,13 @@ where
309
313
310
314
// Check the qualifs of the value of `const` items.
311
315
if let Some ( ct) = constant. literal . const_for_ty ( ) {
312
- if let ty:: ConstKind :: Unevaluated ( ty:: Unevaluated { def, substs_ : _, promoted : None } ) =
313
- ct. val
314
- {
316
+ if let ty:: ConstKind :: Unevaluated ( ty:: Unevaluated { def, substs_ : _, promoted } ) = ct. val {
317
+ // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
318
+ // only for `NeedsNonConstDrop` with precise drop checking. This is the only const
319
+ // check performed after the promotion. Verify that with an assertion.
320
+ assert ! ( promoted. is_none( ) || Q :: ALLOW_PROMOTED ) ;
315
321
// Don't peek inside trait associated constants.
316
- if cx. tcx . trait_of_item ( def. did ) . is_none ( ) {
322
+ if promoted . is_none ( ) && cx. tcx . trait_of_item ( def. did ) . is_none ( ) {
317
323
let qualifs = if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
318
324
cx. tcx . at ( constant. span ) . mir_const_qualif_const_arg ( ( did, param_did) )
319
325
} else {
0 commit comments