@@ -45,6 +45,7 @@ use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
45
45
use rustc_trait_selection:: traits:: ObligationCtxt ;
46
46
use tracing:: debug;
47
47
48
+ use crate :: errors:: AlignOnFields ;
48
49
use crate :: { errors, fluent_generated as fluent} ;
49
50
50
51
#[ derive( LintDiagnostic ) ]
@@ -199,8 +200,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
199
200
Attribute :: Parsed ( AttributeKind :: ExportName { span : attr_span, .. } ) => {
200
201
self . check_export_name ( hir_id, * attr_span, span, target)
201
202
}
202
- Attribute :: Parsed ( AttributeKind :: Align { align, span : repr_span } ) => {
203
- self . check_align ( span, target, * align, * repr_span )
203
+ Attribute :: Parsed ( AttributeKind :: Align { align, span : attr_span } ) => {
204
+ self . check_align ( span, hir_id , target, * align, * attr_span )
204
205
}
205
206
Attribute :: Parsed ( AttributeKind :: LinkSection { span : attr_span, .. } ) => {
206
207
self . check_link_section ( hir_id, * attr_span, span, target)
@@ -1948,22 +1949,37 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1948
1949
}
1949
1950
1950
1951
/// Checks if the `#[align]` attributes on `item` are valid.
1951
- fn check_align ( & self , span : Span , target : Target , align : Align , repr_span : Span ) {
1952
+ fn check_align (
1953
+ & self ,
1954
+ span : Span ,
1955
+ hir_id : HirId ,
1956
+ target : Target ,
1957
+ align : Align ,
1958
+ attr_span : Span ,
1959
+ ) {
1952
1960
match target {
1953
1961
Target :: Fn | Target :: Method ( _) | Target :: ForeignFn => { }
1962
+ Target :: Field => {
1963
+ self . tcx . emit_node_span_lint (
1964
+ UNUSED_ATTRIBUTES ,
1965
+ hir_id,
1966
+ attr_span,
1967
+ AlignOnFields { span } ,
1968
+ ) ;
1969
+ }
1954
1970
Target :: Struct | Target :: Union | Target :: Enum => {
1955
1971
self . dcx ( ) . emit_err ( errors:: AlignShouldBeReprAlign {
1956
- span : repr_span ,
1972
+ span : attr_span ,
1957
1973
item : target. name ( ) ,
1958
1974
align_bytes : align. bytes ( ) ,
1959
1975
} ) ;
1960
1976
}
1961
1977
_ => {
1962
- self . dcx ( ) . emit_err ( errors:: AlignAttrApplication { hint_span : repr_span , span } ) ;
1978
+ self . dcx ( ) . emit_err ( errors:: AlignAttrApplication { hint_span : attr_span , span } ) ;
1963
1979
}
1964
1980
}
1965
1981
1966
- self . check_align_value ( align, repr_span ) ;
1982
+ self . check_align_value ( align, attr_span ) ;
1967
1983
}
1968
1984
1969
1985
/// Checks if the `#[repr]` attributes on `item` are valid.
0 commit comments