@@ -46,6 +46,9 @@ pub trait Qualif {
4646 /// Whether this `Qualif` is cleared when a local is moved from.
4747 const IS_CLEARED_ON_MOVE : bool = false ;
4848
49+ /// Whether this `Qualif` might be evaluated after the promotion and can encounter a promoted.
50+ const ALLOW_PROMOTED : bool = false ;
51+
4952 /// Extracts the field of `ConstQualifs` that corresponds to this `Qualif`.
5053 fn in_qualifs ( qualifs : & ConstQualifs ) -> bool ;
5154
@@ -129,6 +132,7 @@ pub struct NeedsNonConstDrop;
129132impl Qualif for NeedsNonConstDrop {
130133 const ANALYSIS_NAME : & ' static str = "flow_needs_nonconst_drop" ;
131134 const IS_CLEARED_ON_MOVE : bool = true ;
135+ const ALLOW_PROMOTED : bool = true ;
132136
133137 fn in_qualifs ( qualifs : & ConstQualifs ) -> bool {
134138 qualifs. needs_non_const_drop
@@ -309,11 +313,13 @@ where
309313
310314 // Check the qualifs of the value of `const` items.
311315 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 ) ;
315321 // 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 ( ) {
317323 let qualifs = if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
318324 cx. tcx . at ( constant. span ) . mir_const_qualif_const_arg ( ( did, param_did) )
319325 } else {
0 commit comments