@@ -346,32 +346,41 @@ where
346
346
} ;
347
347
348
348
// Check the qualifs of the value of `const` items.
349
- if let Some ( ct) = constant. literal . const_for_ty ( ) {
350
- if let ty:: ConstKind :: Unevaluated ( ty:: Unevaluated { def, substs : _, promoted : _ } ) =
351
- ct. kind ( )
352
- {
353
- // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
354
- // only for `NeedsNonConstDrop` with precise drop checking. This is the only const
355
- // check performed after the promotion. Verify that with an assertion.
356
-
357
- // Don't peek inside trait associated constants.
358
- if cx. tcx . trait_of_item ( def. did ) . is_none ( ) {
359
- let qualifs = if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
360
- cx. tcx . at ( constant. span ) . mir_const_qualif_const_arg ( ( did, param_did) )
361
- } else {
362
- cx. tcx . at ( constant. span ) . mir_const_qualif ( def. did )
363
- } ;
364
-
365
- if !Q :: in_qualifs ( & qualifs) {
366
- return false ;
367
- }
349
+ let uneval = match constant. literal {
350
+ ConstantKind :: Ty ( ct) if matches ! ( ct. kind( ) , ty:: ConstKind :: Unevaluated ( _) ) => {
351
+ let ty:: ConstKind :: Unevaluated ( uv) = ct. kind ( ) else { unreachable ! ( ) } ;
368
352
369
- // Just in case the type is more specific than
370
- // the definition, e.g., impl associated const
371
- // with type parameters, take it into account.
353
+ Some ( uv. expand ( ) )
354
+ }
355
+ ConstantKind :: Ty ( _) => None ,
356
+ ConstantKind :: Unevaluated ( uv, _) => Some ( uv) ,
357
+ ConstantKind :: Val ( ..) => None ,
358
+ } ;
359
+
360
+ if let Some ( ty:: Unevaluated { def, substs : _, promoted } ) = uneval {
361
+ // Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
362
+ // only for `NeedsNonConstDrop` with precise drop checking. This is the only const
363
+ // check performed after the promotion. Verify that with an assertion.
364
+ assert ! ( promoted. is_none( ) || Q :: ALLOW_PROMOTED ) ;
365
+
366
+ // Don't peek inside trait associated constants.
367
+ if promoted. is_none ( ) && cx. tcx . trait_of_item ( def. did ) . is_none ( ) {
368
+ let qualifs = if let Some ( ( did, param_did) ) = def. as_const_arg ( ) {
369
+ cx. tcx . at ( constant. span ) . mir_const_qualif_const_arg ( ( did, param_did) )
370
+ } else {
371
+ cx. tcx . at ( constant. span ) . mir_const_qualif ( def. did )
372
+ } ;
373
+
374
+ if !Q :: in_qualifs ( & qualifs) {
375
+ return false ;
372
376
}
377
+
378
+ // Just in case the type is more specific than
379
+ // the definition, e.g., impl associated const
380
+ // with type parameters, take it into account.
373
381
}
374
382
}
383
+
375
384
// Otherwise use the qualifs of the type.
376
385
Q :: in_any_value_of_ty ( cx, constant. literal . ty ( ) )
377
386
}
0 commit comments