diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-07-14 18:05:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-14 18:05:45 +0200 |
| commit | 16b3f476583212d093d80fbf24ccf8cd35dc26ba (patch) | |
| tree | b7f503def1538fb067016d49d5999da3e9caf097 /compiler/rustc_passes/src/check_attr.rs | |
| parent | bbda0c9fb55dcf78b14a00288568d9ce5651fbf7 (diff) | |
| parent | a5ab6829c6f5c484dc68fdc7ab86057ad1941643 (diff) | |
| download | rust-16b3f476583212d093d80fbf24ccf8cd35dc26ba.tar.gz rust-16b3f476583212d093d80fbf24ccf8cd35dc26ba.zip | |
Rollup merge of #143868 - jdonszelmann:fix-align-on-fields, r=workingjubilee
warn on align on fields to avoid breaking changes r? `@workingjubilee`
Diffstat (limited to 'compiler/rustc_passes/src/check_attr.rs')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index e19d6fa5540..820255afe27 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -45,6 +45,7 @@ use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs}; use rustc_trait_selection::traits::ObligationCtxt; use tracing::debug; +use crate::errors::AlignOnFields; use crate::{errors, fluent_generated as fluent}; #[derive(LintDiagnostic)] @@ -207,8 +208,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::ExportName { span: attr_span, .. }) => { self.check_export_name(hir_id, *attr_span, span, target) } - Attribute::Parsed(AttributeKind::Align { align, span: repr_span }) => { - self.check_align(span, target, *align, *repr_span) + Attribute::Parsed(AttributeKind::Align { align, span: attr_span }) => { + self.check_align(span, hir_id, target, *align, *attr_span) } Attribute::Parsed(AttributeKind::LinkSection { span: attr_span, .. }) => { self.check_link_section(hir_id, *attr_span, span, target) @@ -1953,22 +1954,37 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } /// Checks if the `#[align]` attributes on `item` are valid. - fn check_align(&self, span: Span, target: Target, align: Align, repr_span: Span) { + fn check_align( + &self, + span: Span, + hir_id: HirId, + target: Target, + align: Align, + attr_span: Span, + ) { match target { Target::Fn | Target::Method(_) | Target::ForeignFn => {} + Target::Field => { + self.tcx.emit_node_span_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr_span, + AlignOnFields { span }, + ); + } Target::Struct | Target::Union | Target::Enum => { self.dcx().emit_err(errors::AlignShouldBeReprAlign { - span: repr_span, + span: attr_span, item: target.name(), align_bytes: align.bytes(), }); } _ => { - self.dcx().emit_err(errors::AlignAttrApplication { hint_span: repr_span, span }); + self.dcx().emit_err(errors::AlignAttrApplication { hint_span: attr_span, span }); } } - self.check_align_value(align, repr_span); + self.check_align_value(align, attr_span); } /// Checks if the `#[repr]` attributes on `item` are valid. |
