about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2023-04-16 06:30:45 +0000
committerDeadbeef <ent3rm4n@gmail.com>2023-04-16 06:31:08 +0000
commitdda89945b733897796250c46ca3cca8dcc6abb8a (patch)
tree3416ffcd7d14457e400d00d0fb270ebd883c2a10
parentb59ec166adec6b1348421d7b558ad434351839be (diff)
downloadrust-dda89945b733897796250c46ca3cca8dcc6abb8a.tar.gz
rust-dda89945b733897796250c46ca3cca8dcc6abb8a.zip
Allow all associated functions and add test
-rw-r--r--compiler/rustc_passes/messages.ftl10
-rw-r--r--compiler/rustc_passes/src/check_attr.rs4
-rw-r--r--compiler/rustc_passes/src/errors.rs4
-rw-r--r--tests/codegen/align-fn.rs31
4 files changed, 38 insertions, 11 deletions
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl
index 0d706996810..055682a1509 100644
--- a/compiler/rustc_passes/messages.ftl
+++ b/compiler/rustc_passes/messages.ftl
@@ -627,13 +627,9 @@ passes_attr_application_struct_enum_union =
     attribute should be applied to a struct, enum, or union
     .label = not a struct, enum, or union
 
-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_attr_application_struct_enum_function_method_union =
+    attribute should be applied to a struct, enum, function, associated function, or union
+    .label = not a struct, enum, function, associated function, 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 a03c991d3be..085a28626ea 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -1745,10 +1745,10 @@ impl CheckAttrVisitor<'_> {
                         | Target::Union
                         | Target::Enum
                         | Target::Fn
-                        | Target::Method(MethodKind::Inherent) => continue,
+                        | Target::Method(_) => continue,
                         _ => {
                             self.tcx.sess.emit_err(
-                                errors::AttrApplication::StructEnumFunctionInherentMethodUnion {
+                                errors::AttrApplication::StructEnumFunctionMethodUnion {
                                     hint_span: hint.span(),
                                     span,
                                 },
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index 27039a2a5a2..e8603b3a2f1 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_inherent_method_union, code = "E0517")]
-    StructEnumFunctionInherentMethodUnion {
+    #[diag(passes_attr_application_struct_enum_function_method_union, code = "E0517")]
+    StructEnumFunctionMethodUnion {
         #[primary_span]
         hint_span: Span,
         #[label]
diff --git a/tests/codegen/align-fn.rs b/tests/codegen/align-fn.rs
index 7238e7f53c3..f3cf614e185 100644
--- a/tests/codegen/align-fn.rs
+++ b/tests/codegen/align-fn.rs
@@ -15,4 +15,35 @@ impl A {
     #[no_mangle]
     #[repr(align(16))]
     pub fn method_align(self) {}
+
+    // CHECK: align 16
+    #[no_mangle]
+    #[repr(align(16))]
+    pub fn associated_fn() {}
+}
+
+trait T: Sized {
+    fn trait_fn() {}
+
+    // CHECK: align 32
+    #[repr(align(32))]
+    fn trait_method(self) {}
+}
+
+impl T for A {
+    // CHECK: align 16
+    #[no_mangle]
+    #[repr(align(16))]
+    fn trait_fn() {}
+
+    // CHECK: align 16
+    #[no_mangle]
+    #[repr(align(16))]
+    fn trait_method(self) {}
+}
+
+impl T for () {}
+
+pub fn foo() {
+    ().trait_method();
 }