@@ -142,6 +142,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
142
142
}
143
143
Attribute :: Parsed ( AttributeKind :: Repr ( _) ) => { /* handled below this loop and elsewhere */
144
144
}
145
+ Attribute :: Parsed ( AttributeKind :: Align { align, span : repr_span } ) => {
146
+ self . check_align ( span, target, * align, * repr_span)
147
+ }
148
+
145
149
Attribute :: Parsed (
146
150
AttributeKind :: BodyStability { .. }
147
151
| AttributeKind :: ConstStabilityIndirect
@@ -636,6 +640,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
636
640
sym:: naked,
637
641
sym:: instruction_set,
638
642
sym:: repr,
643
+ sym:: align,
639
644
sym:: rustc_std_internal_symbol,
640
645
// code generation
641
646
sym:: cold,
@@ -672,7 +677,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
672
677
// this check can be part of the parser and be removed here
673
678
match other_attr {
674
679
Attribute :: Parsed (
675
- AttributeKind :: Deprecation { .. } | AttributeKind :: Repr { .. } ,
680
+ AttributeKind :: Deprecation { .. }
681
+ | AttributeKind :: Repr { .. }
682
+ | AttributeKind :: Align { .. } ,
676
683
) => {
677
684
continue ;
678
685
}
@@ -1947,6 +1954,28 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1947
1954
}
1948
1955
}
1949
1956
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
+
1950
1979
/// Checks if the `#[repr]` attributes on `item` are valid.
1951
1980
fn check_repr (
1952
1981
& self ,
@@ -1999,23 +2028,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1999
2028
match target {
2000
2029
Target :: Struct | Target :: Union | Target :: Enum => { }
2001
2030
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
+ } ) ;
2011
2035
}
2012
2036
_ => {
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
+ } ) ;
2019
2041
}
2020
2042
}
2021
2043
@@ -2073,21 +2095,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2073
2095
match target {
2074
2096
Target :: Struct | Target :: Union | Target :: Enum => continue ,
2075
2097
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
+ } ) ;
2083
2102
}
2084
2103
_ => {
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
+ } ) ;
2091
2108
}
2092
2109
}
2093
2110
}
0 commit comments