@@ -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 ) ]
@@ -207,8 +208,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
207
208
Attribute :: Parsed ( AttributeKind :: ExportName { span : attr_span, .. } ) => {
208
209
self . check_export_name ( hir_id, * attr_span, span, target)
209
210
}
210
- Attribute :: Parsed ( AttributeKind :: Align { align, span : repr_span } ) => {
211
- self . check_align ( span, target, * align, * repr_span )
211
+ Attribute :: Parsed ( AttributeKind :: Align { align, span : attr_span } ) => {
212
+ self . check_align ( span, hir_id , target, * align, * attr_span )
212
213
}
213
214
Attribute :: Parsed ( AttributeKind :: LinkSection { span : attr_span, .. } ) => {
214
215
self . check_link_section ( hir_id, * attr_span, span, target)
@@ -1953,22 +1954,37 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1953
1954
}
1954
1955
1955
1956
/// Checks if the `#[align]` attributes on `item` are valid.
1956
- fn check_align ( & self , span : Span , target : Target , align : Align , repr_span : Span ) {
1957
+ fn check_align (
1958
+ & self ,
1959
+ span : Span ,
1960
+ hir_id : HirId ,
1961
+ target : Target ,
1962
+ align : Align ,
1963
+ attr_span : Span ,
1964
+ ) {
1957
1965
match target {
1958
1966
Target :: Fn | Target :: Method ( _) | Target :: ForeignFn => { }
1967
+ Target :: Field => {
1968
+ self . tcx . emit_node_span_lint (
1969
+ UNUSED_ATTRIBUTES ,
1970
+ hir_id,
1971
+ attr_span,
1972
+ AlignOnFields { span } ,
1973
+ ) ;
1974
+ }
1959
1975
Target :: Struct | Target :: Union | Target :: Enum => {
1960
1976
self . dcx ( ) . emit_err ( errors:: AlignShouldBeReprAlign {
1961
- span : repr_span ,
1977
+ span : attr_span ,
1962
1978
item : target. name ( ) ,
1963
1979
align_bytes : align. bytes ( ) ,
1964
1980
} ) ;
1965
1981
}
1966
1982
_ => {
1967
- self . dcx ( ) . emit_err ( errors:: AlignAttrApplication { hint_span : repr_span , span } ) ;
1983
+ self . dcx ( ) . emit_err ( errors:: AlignAttrApplication { hint_span : attr_span , span } ) ;
1968
1984
}
1969
1985
}
1970
1986
1971
- self . check_align_value ( align, repr_span ) ;
1987
+ self . check_align_value ( align, attr_span ) ;
1972
1988
}
1973
1989
1974
1990
/// Checks if the `#[repr]` attributes on `item` are valid.
0 commit comments