Skip to content

Commit b59ec16

Browse files
committed
allow repr(align = x) on inherent methods
1 parent d558796 commit b59ec16

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ passes_attr_application_struct_enum_function_union =
631631
attribute should be applied to a struct, enum, function, or union
632632
.label = not a struct, enum, function, or union
633633
634+
passes_attr_application_struct_enum_function_inherent_method_union =
635+
attribute should be applied to a struct, enum, function, inherent method, or union
636+
.label = not a struct, enum, function, inherent method, or union
637+
634638
passes_transparent_incompatible =
635639
transparent {$target} cannot have other repr hints
636640

compiler/rustc_passes/src/check_attr.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,9 @@ impl CheckAttrVisitor<'_> {
17281728
}
17291729
}
17301730
sym::align => {
1731-
if let (Target::Fn, false) = (target, self.tcx.features().fn_align) {
1731+
if let (Target::Fn | Target::Method(MethodKind::Inherent), false) =
1732+
(target, self.tcx.features().fn_align)
1733+
{
17321734
feature_err(
17331735
&self.tcx.sess.parse_sess,
17341736
sym::fn_align,
@@ -1739,10 +1741,14 @@ impl CheckAttrVisitor<'_> {
17391741
}
17401742

17411743
match target {
1742-
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
1744+
Target::Struct
1745+
| Target::Union
1746+
| Target::Enum
1747+
| Target::Fn
1748+
| Target::Method(MethodKind::Inherent) => continue,
17431749
_ => {
17441750
self.tcx.sess.emit_err(
1745-
errors::AttrApplication::StructEnumFunctionUnion {
1751+
errors::AttrApplication::StructEnumFunctionInherentMethodUnion {
17461752
hint_span: hint.span(),
17471753
span,
17481754
},

compiler/rustc_passes/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,8 @@ pub enum AttrApplication {
13551355
#[label]
13561356
span: Span,
13571357
},
1358-
#[diag(passes_attr_application_struct_enum_function_union, code = "E0517")]
1359-
StructEnumFunctionUnion {
1358+
#[diag(passes_attr_application_struct_enum_function_inherent_method_union, code = "E0517")]
1359+
StructEnumFunctionInherentMethodUnion {
13601360
#[primary_span]
13611361
hint_span: Span,
13621362
#[label]

tests/codegen/align-fn.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@
77
#[no_mangle]
88
#[repr(align(16))]
99
pub fn fn_align() {}
10+
11+
pub struct A;
12+
13+
impl A {
14+
// CHECK: align 16
15+
#[no_mangle]
16+
#[repr(align(16))]
17+
pub fn method_align(self) {}
18+
}

0 commit comments

Comments
 (0)