Skip to content

Commit 308ef8d

Browse files
Remove repr(align) code
1 parent 4e97337 commit 308ef8d

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::{Align, ExternAbi};
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_attr_data_structures::{
7-
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, ReprAttr, UsedBy, find_attr,
7+
AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, UsedBy, find_attr,
88
};
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
@@ -109,14 +109,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
109109

110110
if let hir::Attribute::Parsed(p) = attr {
111111
match p {
112-
AttributeKind::Repr(reprs) => {
113-
codegen_fn_attrs.alignment = reprs
114-
.iter()
115-
.filter_map(
116-
|(r, _)| if let ReprAttr::ReprAlign(x) = r { Some(*x) } else { None },
117-
)
118-
.max();
119-
}
120112
AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
121113
AttributeKind::ExportName { name, .. } => {
122114
codegen_fn_attrs.export_name = Some(*name);

compiler/rustc_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ passes_abi_ne =
1313
passes_abi_of =
1414
fn_abi_of({$fn_name}) = {$fn_abi}
1515
16+
passes_align_attr_application =
17+
`#[align(...)]` should be applied to a function item
18+
.label = not a function item
19+
1620
passes_align_should_be_repr_align =
1721
`#[align(...)]` is not supported on {$item} items
1822
.suggestion = use `#[repr(align(...))]` instead

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,10 +1896,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
18961896
});
18971897
}
18981898
_ => {
1899-
self.dcx().emit_err(errors::AttrApplication::StructEnumUnion {
1900-
hint_span: repr_span,
1901-
span,
1902-
});
1899+
self.dcx().emit_err(errors::AlignAttrApplication { hint_span: repr_span, span });
19031900
}
19041901
}
19051902

compiler/rustc_passes/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,3 +1838,12 @@ pub(crate) struct AlignShouldBeReprAlign {
18381838
pub item: &'static str,
18391839
pub align_bytes: u64,
18401840
}
1841+
1842+
#[derive(Diagnostic)]
1843+
#[diag(passes_align_attr_application)]
1844+
pub(crate) struct AlignAttrApplication {
1845+
#[primary_span]
1846+
pub hint_span: Span,
1847+
#[label]
1848+
pub span: Span,
1849+
}

tests/ui/attributes/malformed-fn-align.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ fn f4() {}
2323

2424
#[align(16)] //~ ERROR `#[align(...)]` is not supported on struct items
2525
struct S1;
26+
27+
#[align(32)] //~ ERROR `#[align(...)]` should be applied to a function item
28+
const FOO: i32 = 42;
29+
30+
#[align(32)] //~ ERROR `#[align(...)]` should be applied to a function item
31+
mod test {}
32+
33+
#[align(32)] //~ ERROR `#[align(...)]` should be applied to a function item
34+
use ::std::iter;

tests/ui/attributes/malformed-fn-align.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,31 @@ LL - #[align(16)]
6161
LL + #[repr(align(16))]
6262
|
6363

64-
error: aborting due to 7 previous errors
64+
error: `#[align(...)]` should be applied to a function item
65+
--> $DIR/malformed-fn-align.rs:27:1
66+
|
67+
LL | #[align(32)]
68+
| ^^^^^^^^^^^^
69+
LL | const FOO: i32 = 42;
70+
| -------------------- not a function item
71+
72+
error: `#[align(...)]` should be applied to a function item
73+
--> $DIR/malformed-fn-align.rs:30:1
74+
|
75+
LL | #[align(32)]
76+
| ^^^^^^^^^^^^
77+
LL | mod test {}
78+
| ----------- not a function item
79+
80+
error: `#[align(...)]` should be applied to a function item
81+
--> $DIR/malformed-fn-align.rs:33:1
82+
|
83+
LL | #[align(32)]
84+
| ^^^^^^^^^^^^
85+
LL | use ::std::iter;
86+
| ---------------- not a function item
87+
88+
error: aborting due to 10 previous errors
6589

6690
Some errors have detailed explanations: E0539, E0589, E0805.
6791
For more information about an error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)