Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions gcc/rust/expand/rust-derive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rust-derive-ord.h"
#include "rust-derive-partial-eq.h"
#include "rust-derive-hash.h"
#include "rust-system.h"

namespace Rust {
namespace AST {
Expand All @@ -39,6 +40,16 @@ DeriveVisitor::derive (Item &item, const Attribute &attr,
{
auto loc = attr.get_locus ();

using kind = AST::Item::Kind;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use an uppercase Kind alias here to avoid confusion.

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:
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/expand/rust-expand-visitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "rust-expand-visitor.h"
#include "rust-ast-fragment.h"
#include "rust-diagnostics.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no modification within rust-expand-visitor.cc, is this include really required ?

#include "rust-item.h"
#include "rust-proc-macro.h"
#include "rust-attributes.h"
Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/issue-3971.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[lang = "copy"]
trait Copy {}

#[derive(Copy)]
// { dg-error "derive may only be applied to structs, enums and unions" "" { target *-*-* } .-1 }

pub fn check_ge(a: i32, b: i32) -> bool {
a >= b
}

Loading