@@ -142,6 +142,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
142142 }
143143 Attribute :: Parsed ( AttributeKind :: Repr ( _) ) => { /* handled below this loop and elsewhere */
144144 }
145+ Attribute :: Parsed ( AttributeKind :: Align { align, span : repr_span } ) => {
146+ self . check_align ( span, target, * align, * repr_span)
147+ }
148+
145149 Attribute :: Parsed (
146150 AttributeKind :: BodyStability { .. }
147151 | AttributeKind :: ConstStabilityIndirect
@@ -636,6 +640,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
636640 sym:: naked,
637641 sym:: instruction_set,
638642 sym:: repr,
643+ sym:: align,
639644 sym:: rustc_std_internal_symbol,
640645 // code generation
641646 sym:: cold,
@@ -672,7 +677,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
672677 // this check can be part of the parser and be removed here
673678 match other_attr {
674679 Attribute :: Parsed (
675- AttributeKind :: Deprecation { .. } | AttributeKind :: Repr { .. } ,
680+ AttributeKind :: Deprecation { .. }
681+ | AttributeKind :: Repr { .. }
682+ | AttributeKind :: Align { .. } ,
676683 ) => {
677684 continue ;
678685 }
@@ -1947,6 +1954,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19471954 }
19481955 }
19491956
1957+ /// Checks if the `#[align]` attributes on `item` are valid.
1958+ fn check_align ( & self , span : Span , target : Target , align : Align , repr_span : Span ) {
1959+ match target {
1960+ Target :: Fn | Target :: Method ( _) => { }
1961+ Target :: Struct | Target :: Union | Target :: Enum => {
1962+ self . dcx ( ) . emit_err ( errors:: AlignShouldBeReprAlign {
1963+ span : repr_span,
1964+ item : target. name ( ) ,
1965+ align_bytes : align. bytes ( ) ,
1966+ } ) ;
1967+ }
1968+ _ => {
1969+ self . dcx ( ) . emit_err ( errors:: AttrApplication :: StructEnumUnion {
1970+ hint_span : repr_span,
1971+ span,
1972+ } ) ;
1973+ }
1974+ }
1975+
1976+ self . check_align_value ( align, repr_span) ;
1977+ }
1978+
19501979 /// Checks if the `#[repr]` attributes on `item` are valid.
19511980 fn check_repr (
19521981 & self ,
@@ -1999,23 +2028,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19992028 match target {
20002029 Target :: Struct | Target :: Union | Target :: Enum => { }
20012030 Target :: Fn | Target :: Method ( _) => {
2002- if !self . tcx . features ( ) . fn_align ( ) {
2003- feature_err (
2004- & self . tcx . sess ,
2005- sym:: fn_align,
2006- * repr_span,
2007- fluent:: passes_repr_align_function,
2008- )
2009- . emit ( ) ;
2010- }
2031+ self . dcx ( ) . emit_err ( errors:: ReprAlignShouldBeAlign {
2032+ span : * repr_span,
2033+ item : target. name ( ) ,
2034+ } ) ;
20112035 }
20122036 _ => {
2013- self . dcx ( ) . emit_err (
2014- errors:: AttrApplication :: StructEnumFunctionMethodUnion {
2015- hint_span : * repr_span,
2016- span,
2017- } ,
2018- ) ;
2037+ self . dcx ( ) . emit_err ( errors:: AttrApplication :: StructEnumUnion {
2038+ hint_span : * repr_span,
2039+ span,
2040+ } ) ;
20192041 }
20202042 }
20212043
@@ -2073,21 +2095,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
20732095 match target {
20742096 Target :: Struct | Target :: Union | Target :: Enum => continue ,
20752097 Target :: Fn | Target :: Method ( _) => {
2076- feature_err (
2077- & self . tcx . sess ,
2078- sym:: fn_align,
2079- * repr_span,
2080- fluent:: passes_repr_align_function,
2081- )
2082- . emit ( ) ;
2098+ self . dcx ( ) . emit_err ( errors:: ReprAlignShouldBeAlign {
2099+ span : * repr_span,
2100+ item : target. name ( ) ,
2101+ } ) ;
20832102 }
20842103 _ => {
2085- self . dcx ( ) . emit_err (
2086- errors:: AttrApplication :: StructEnumFunctionMethodUnion {
2087- hint_span : * repr_span,
2088- span,
2089- } ,
2090- ) ;
2104+ self . dcx ( ) . emit_err ( errors:: AttrApplication :: StructEnumUnion {
2105+ hint_span : * repr_span,
2106+ span,
2107+ } ) ;
20912108 }
20922109 }
20932110 }
0 commit comments