diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 0e523468760..bf7f3d9827d 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -912,6 +912,12 @@ AttributeChecker::visit (AST::Function &fun) { check_link_section_attribute (attribute); } + else if (result.name == Attrs::REPR) + { + rust_error_at ( + attribute.get_locus (), + "attribute should be applied to a struct, enum, or union"); + } } if (fun.has_body ()) diff --git a/gcc/testsuite/rust/compile/issue-4232.rs b/gcc/testsuite/rust/compile/issue-4232.rs new file mode 100644 index 00000000000..fa12538808d --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-4232.rs @@ -0,0 +1,3 @@ +// { dg-options "-w" } +#[repr(C)] // { dg-error "attribute should be applied to a struct, enum, or union" } +fn a() {} \ No newline at end of file