@@ -43,6 +43,7 @@ use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
43
43
use rustc_trait_selection::traits::ObligationCtxt;
44
44
use tracing::debug;
45
45
46
+ use crate::errors::AlignOnFields;
46
47
use crate::{errors, fluent_generated as fluent};
47
48
48
49
#[derive(LintDiagnostic)]
@@ -197,8 +198,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
197
198
Attribute::Parsed(AttributeKind::ExportName { span: attr_span, .. }) => {
198
199
self.check_export_name(hir_id, *attr_span, span, target)
199
200
}
200
- Attribute::Parsed(AttributeKind::Align { align, span: repr_span }) => {
201
- self.check_align(span, target, *align, *repr_span )
201
+ Attribute::Parsed(AttributeKind::Align { align, span: attr_span }) => {
202
+ self.check_align(span, hir_id, target, *align, *attr_span )
202
203
}
203
204
Attribute::Parsed(AttributeKind::LinkSection { span: attr_span, .. }) => {
204
205
self.check_link_section(hir_id, *attr_span, span, target)
@@ -1933,22 +1934,37 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1933
1934
}
1934
1935
1935
1936
/// Checks if the `#[align]` attributes on `item` are valid.
1936
- fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) {
1937
+ fn check_align(
1938
+ &self,
1939
+ span: Span,
1940
+ hir_id: HirId,
1941
+ target: Target,
1942
+ align: Align,
1943
+ attr_span: Span,
1944
+ ) {
1937
1945
match target {
1938
1946
Target::Fn | Target::Method(_) | Target::ForeignFn => {}
1947
+ Target::Field => {
1948
+ self.tcx.emit_node_span_lint(
1949
+ UNUSED_ATTRIBUTES,
1950
+ hir_id,
1951
+ attr_span,
1952
+ AlignOnFields { span },
1953
+ );
1954
+ }
1939
1955
Target::Struct | Target::Union | Target::Enum => {
1940
1956
self.dcx().emit_err(errors::AlignShouldBeReprAlign {
1941
- span: repr_span ,
1957
+ span: attr_span ,
1942
1958
item: target.name(),
1943
1959
align_bytes: align.bytes(),
1944
1960
});
1945
1961
}
1946
1962
_ => {
1947
- self.dcx().emit_err(errors::AlignAttrApplication { hint_span: repr_span , span });
1963
+ self.dcx().emit_err(errors::AlignAttrApplication { hint_span: attr_span , span });
1948
1964
}
1949
1965
}
1950
1966
1951
- self.check_align_value(align, repr_span );
1967
+ self.check_align_value(align, attr_span );
1952
1968
}
1953
1969
1954
1970
/// Checks if the `#[repr]` attributes on `item` are valid.
0 commit comments