Skip to content

Commit

Permalink
Allow all associated functions and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Apr 16, 2023
1 parent b59ec16 commit dda8994
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
10 changes: 3 additions & 7 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
31 changes: 31 additions & 0 deletions tests/codegen/align-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit dda8994

Please sign in to comment.