Allow all associated functions and add test

This commit is contained in:
Deadbeef 2023-04-16 06:30:45 +00:00
parent b59ec166ad
commit dda89945b7
4 changed files with 38 additions and 11 deletions

View file

@ -627,13 +627,9 @@ passes_attr_application_struct_enum_union =
attribute should be applied to a struct, enum, or union attribute should be applied to a struct, enum, or union
.label = not a struct, enum, or union .label = not a struct, enum, or union
passes_attr_application_struct_enum_function_union = passes_attr_application_struct_enum_function_method_union =
attribute should be applied to a struct, enum, function, or union attribute should be applied to a struct, enum, function, associated function, or union
.label = not a struct, enum, function, or union .label = not a struct, enum, function, associated 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 = passes_transparent_incompatible =
transparent {$target} cannot have other repr hints transparent {$target} cannot have other repr hints

View file

@ -1745,10 +1745,10 @@ impl CheckAttrVisitor<'_> {
| Target::Union | Target::Union
| Target::Enum | Target::Enum
| Target::Fn | Target::Fn
| Target::Method(MethodKind::Inherent) => continue, | Target::Method(_) => continue,
_ => { _ => {
self.tcx.sess.emit_err( self.tcx.sess.emit_err(
errors::AttrApplication::StructEnumFunctionInherentMethodUnion { errors::AttrApplication::StructEnumFunctionMethodUnion {
hint_span: hint.span(), hint_span: hint.span(),
span, span,
}, },

View file

@ -1355,8 +1355,8 @@ pub enum AttrApplication {
#[label] #[label]
span: Span, span: Span,
}, },
#[diag(passes_attr_application_struct_enum_function_inherent_method_union, code = "E0517")] #[diag(passes_attr_application_struct_enum_function_method_union, code = "E0517")]
StructEnumFunctionInherentMethodUnion { StructEnumFunctionMethodUnion {
#[primary_span] #[primary_span]
hint_span: Span, hint_span: Span,
#[label] #[label]

View file

@ -15,4 +15,35 @@ impl A {
#[no_mangle] #[no_mangle]
#[repr(align(16))] #[repr(align(16))]
pub fn method_align(self) {} 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();
} }