diff options
author | Deadbeef <ent3rm4n@gmail.com> | 2023-04-14 06:39:16 +0000 |
---|---|---|
committer | Deadbeef <ent3rm4n@gmail.com> | 2023-04-14 06:39:48 +0000 |
commit | b59ec166adec6b1348421d7b558ad434351839be (patch) | |
tree | c10c968f83fbc71569e5daa2946b97b56a5bb10c | |
parent | d558796beb400cceb2a2b8950f35aa518a58a586 (diff) | |
download | rust-b59ec166adec6b1348421d7b558ad434351839be.tar.gz |
allow `repr(align = x)` on inherent methods
-rw-r--r-- | compiler/rustc_passes/messages.ftl | 4 | ||||
-rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 12 | ||||
-rw-r--r-- | compiler/rustc_passes/src/errors.rs | 4 | ||||
-rw-r--r-- | tests/codegen/align-fn.rs | 9 |
4 files changed, 24 insertions, 5 deletions
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index b354dca7cc4..0d706996810 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -631,6 +631,10 @@ passes_attr_application_struct_enum_function_union = attribute should be applied to a struct, enum, function, or union .label = not a struct, enum, function, or union +passes_attr_application_struct_enum_function_inherent_method_union = + attribute should be applied to a struct, enum, function, inherent method, or union + .label = not a struct, enum, function, inherent method, or union + passes_transparent_incompatible = transparent {$target} cannot have other repr hints diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 80a93da2b45..a03c991d3be 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1728,7 +1728,9 @@ impl CheckAttrVisitor<'_> { } } sym::align => { - if let (Target::Fn, false) = (target, self.tcx.features().fn_align) { + if let (Target::Fn | Target::Method(MethodKind::Inherent), false) = + (target, self.tcx.features().fn_align) + { feature_err( &self.tcx.sess.parse_sess, sym::fn_align, @@ -1739,10 +1741,14 @@ impl CheckAttrVisitor<'_> { } match target { - Target::Struct | Target::Union | Target::Enum | Target::Fn => continue, + Target::Struct + | Target::Union + | Target::Enum + | Target::Fn + | Target::Method(MethodKind::Inherent) => continue, _ => { self.tcx.sess.emit_err( - errors::AttrApplication::StructEnumFunctionUnion { + errors::AttrApplication::StructEnumFunctionInherentMethodUnion { hint_span: hint.span(), span, }, diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 139ba8c9677..27039a2a5a2 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1355,8 +1355,8 @@ pub enum AttrApplication { #[label] span: Span, }, - #[diag(passes_attr_application_struct_enum_function_union, code = "E0517")] - StructEnumFunctionUnion { + #[diag(passes_attr_application_struct_enum_function_inherent_method_union, code = "E0517")] + StructEnumFunctionInherentMethodUnion { #[primary_span] hint_span: Span, #[label] diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs index c5886cf2808..7238e7f53c3 100644 --- a/tests/codegen/align-fn.rs +++ b/tests/codegen/align-fn.rs @@ -7,3 +7,12 @@ #[no_mangle] #[repr(align(16))] pub fn fn_align() {} + +pub struct A; + +impl A { + // CHECK: align 16 + #[no_mangle] + #[repr(align(16))] + pub fn method_align(self) {} +} |