Derive may only be applied to structs, enums and unions.
gcc/rust/ChangeLog:
* expand/rust-derive.cc (DeriveVisitor::derive):
Add check and error.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3971.rs: New test.
Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
#include "rust-derive-ord.h"
#include "rust-derive-partial-eq.h"
#include "rust-derive-hash.h"
+#include "rust-system.h"
namespace Rust {
namespace AST {
{
auto loc = attr.get_locus ();
+ using Kind = AST::Item::Kind;
+ auto item_kind = item.get_item_kind ();
+ if (item_kind != Kind::Enum && item_kind != Kind::Struct
+ && item_kind != Kind::Union)
+ {
+ rust_error_at (loc,
+ "derive may only be applied to structs, enums and unions");
+ return {};
+ }
+
switch (to_derive)
{
case BuiltinMacro::Clone:
--- /dev/null
+#[lang = "copy"]
+trait Copy {}
+
+// since the macro expansion fails, the current nameres fixpoint error is emitted - just accept it for now
+#[derive(Copy)]
+// { dg-error "derive may only be applied to structs, enums and unions" "" { target *-*-* } .-1 }
+// { dg-excess-errors "could not resolve trait" }
+
+pub fn check_ge(a: i32, b: i32) -> bool {
+ a >= b
+}