@@ -566,14 +566,15 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
566
566
567
567
ProjectionElem :: Field ( ..) |
568
568
ProjectionElem :: Index ( _) => {
569
- if this. mode == Mode :: Fn {
570
- let base_ty = proj. base . ty ( this. mir , this. tcx ) . to_ty ( this. tcx ) ;
571
- if let Some ( def) = base_ty. ty_adt_def ( ) {
572
- if def. is_union ( ) {
573
- this. not_const ( ) ;
574
- }
569
+ let base_ty = proj. base . ty ( this. mir , this. tcx ) . to_ty ( this. tcx ) ;
570
+ // accessing union fields is never allowed inside promoteds
571
+ if let Some ( def) = base_ty. ty_adt_def ( ) {
572
+ if def. is_union ( ) {
573
+ this. add ( Qualif :: NOT_PROMOTABLE ) ;
575
574
}
576
- } else if this. qualif . intersects ( Qualif :: STATIC ) {
575
+ }
576
+ // Only functions may refer to statics directly
577
+ if this. mode != Mode :: Fn && this. qualif . intersects ( Qualif :: STATIC ) {
577
578
span_err ! ( this. tcx. sess, this. span, E0494 ,
578
579
"cannot refer to the interior of another \
579
580
static, use a constant instead") ;
@@ -615,6 +616,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
615
616
} = constant. literal {
616
617
// Don't peek inside trait associated constants.
617
618
if self . tcx . trait_of_item ( def_id) . is_some ( ) {
619
+ self . add ( Qualif :: NOT_PROMOTABLE ) ;
618
620
self . add_type ( ty) ;
619
621
} else {
620
622
let ( bits, _) = self . tcx . at ( constant. span ) . mir_const_qualif ( def_id) ;
0 commit comments