55//! item.
66
77use crate :: errors:: {
8- self , AttributeShouldBeAppliedTo , DebugVisualizerUnreadable , InvalidAttrAtCrateLevel ,
9- ObjectLifetimeErr , OnlyHasEffectOn , TransparentIncompatible , UnrecognizedReprHint ,
8+ self , AttrApplication , DebugVisualizerUnreadable , InvalidAttrAtCrateLevel , ObjectLifetimeErr ,
9+ OnlyHasEffectOn , TransparentIncompatible , UnrecognizedReprHint ,
1010} ;
1111use rustc_ast:: { ast, AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem } ;
1212use rustc_data_structures:: fx:: FxHashMap ;
@@ -1594,12 +1594,17 @@ impl CheckAttrVisitor<'_> {
15941594 continue ;
15951595 }
15961596
1597- let what = match hint. name_or_empty ( ) {
1597+ match hint. name_or_empty ( ) {
15981598 sym:: C => {
15991599 is_c = true ;
16001600 match target {
16011601 Target :: Struct | Target :: Union | Target :: Enum => continue ,
1602- _ => "struct-enum-union" ,
1602+ _ => {
1603+ self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1604+ hint_span : hint. span ( ) ,
1605+ span,
1606+ } ) ;
1607+ }
16031608 }
16041609 }
16051610 sym:: align => {
@@ -1615,20 +1620,30 @@ impl CheckAttrVisitor<'_> {
16151620
16161621 match target {
16171622 Target :: Struct | Target :: Union | Target :: Enum | Target :: Fn => continue ,
1618- _ => "struct-enum-function-union" ,
1623+ _ => {
1624+ self . tcx . sess . emit_err ( AttrApplication :: StructEnumFunctionUnion {
1625+ hint_span : hint. span ( ) ,
1626+ span,
1627+ } ) ;
1628+ }
16191629 }
16201630 }
16211631 sym:: packed => {
16221632 if target != Target :: Struct && target != Target :: Union {
1623- "struct-union"
1633+ self . tcx . sess . emit_err ( AttrApplication :: StructUnion {
1634+ hint_span : hint. span ( ) ,
1635+ span,
1636+ } ) ;
16241637 } else {
16251638 continue ;
16261639 }
16271640 }
16281641 sym:: simd => {
16291642 is_simd = true ;
16301643 if target != Target :: Struct {
1631- "struct"
1644+ self . tcx
1645+ . sess
1646+ . emit_err ( AttrApplication :: Struct { hint_span : hint. span ( ) , span } ) ;
16321647 } else {
16331648 continue ;
16341649 }
@@ -1637,7 +1652,12 @@ impl CheckAttrVisitor<'_> {
16371652 is_transparent = true ;
16381653 match target {
16391654 Target :: Struct | Target :: Union | Target :: Enum => continue ,
1640- _ => "struct-enum-union" ,
1655+ _ => {
1656+ self . tcx . sess . emit_err ( AttrApplication :: StructEnumUnion {
1657+ hint_span : hint. span ( ) ,
1658+ span,
1659+ } ) ;
1660+ }
16411661 }
16421662 }
16431663 sym:: i8
@@ -1654,7 +1674,9 @@ impl CheckAttrVisitor<'_> {
16541674 | sym:: usize => {
16551675 int_reprs += 1 ;
16561676 if target != Target :: Enum {
1657- "enum"
1677+ self . tcx
1678+ . sess
1679+ . emit_err ( AttrApplication :: Enum { hint_span : hint. span ( ) , span } ) ;
16581680 } else {
16591681 continue ;
16601682 }
@@ -1664,12 +1686,6 @@ impl CheckAttrVisitor<'_> {
16641686 continue ;
16651687 }
16661688 } ;
1667-
1668- self . tcx . sess . emit_err ( AttributeShouldBeAppliedTo {
1669- hint_span : hint. span ( ) ,
1670- span,
1671- what,
1672- } ) ;
16731689 }
16741690
16751691 // Just point at all repr hints if there are any incompatibilities.
0 commit comments