Skip to content

Commit dda8994

Browse files
committed
Allow all associated functions and add test
1 parent b59ec16 commit dda8994

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

compiler/rustc_passes/messages.ftl

+3-7
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,9 @@ passes_attr_application_struct_enum_union =
627627
attribute should be applied to a struct, enum, or union
628628
.label = not a struct, enum, or union
629629
630-
passes_attr_application_struct_enum_function_union =
631-
attribute should be applied to a struct, enum, function, or union
632-
.label = not a struct, enum, function, or union
633-
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
630+
passes_attr_application_struct_enum_function_method_union =
631+
attribute should be applied to a struct, enum, function, associated function, or union
632+
.label = not a struct, enum, function, associated function, or union
637633
638634
passes_transparent_incompatible =
639635
transparent {$target} cannot have other repr hints

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1745,10 +1745,10 @@ impl CheckAttrVisitor<'_> {
17451745
| Target::Union
17461746
| Target::Enum
17471747
| Target::Fn
1748-
| Target::Method(MethodKind::Inherent) => continue,
1748+
| Target::Method(_) => continue,
17491749
_ => {
17501750
self.tcx.sess.emit_err(
1751-
errors::AttrApplication::StructEnumFunctionInherentMethodUnion {
1751+
errors::AttrApplication::StructEnumFunctionMethodUnion {
17521752
hint_span: hint.span(),
17531753
span,
17541754
},

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_inherent_method_union, code = "E0517")]
1359-
StructEnumFunctionInherentMethodUnion {
1358+
#[diag(passes_attr_application_struct_enum_function_method_union, code = "E0517")]
1359+
StructEnumFunctionMethodUnion {
13601360
#[primary_span]
13611361
hint_span: Span,
13621362
#[label]

tests/codegen/align-fn.rs

+31
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,35 @@ impl A {
1515
#[no_mangle]
1616
#[repr(align(16))]
1717
pub fn method_align(self) {}
18+
19+
// CHECK: align 16
20+
#[no_mangle]
21+
#[repr(align(16))]
22+
pub fn associated_fn() {}
23+
}
24+
25+
trait T: Sized {
26+
fn trait_fn() {}
27+
28+
// CHECK: align 32
29+
#[repr(align(32))]
30+
fn trait_method(self) {}
31+
}
32+
33+
impl T for A {
34+
// CHECK: align 16
35+
#[no_mangle]
36+
#[repr(align(16))]
37+
fn trait_fn() {}
38+
39+
// CHECK: align 16
40+
#[no_mangle]
41+
#[repr(align(16))]
42+
fn trait_method(self) {}
43+
}
44+
45+
impl T for () {}
46+
47+
pub fn foo() {
48+
().trait_method();
1849
}

0 commit comments

Comments
 (0)