From 25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3 Mon Sep 17 00:00:00 2001 From: Owen Avery Date: Mon, 5 Jun 2023 10:41:43 -0400 Subject: Add error message when derive macro is invoked gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc: Fix comments. (MacroBuiltin::proc_macro_builtin): Add error message. * expand/rust-macro-builtins.h: Fix comments. gcc/testsuite/ChangeLog: * rust/compile/derive_macro8.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/expand/rust-macro-builtins.cc | 9 ++++++--- gcc/rust/expand/rust-macro-builtins.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'gcc/rust') diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index a4e9854..59a1f19 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -106,7 +106,7 @@ std::unordered_map< {"global_allocator", MacroBuiltin::sorry}, {"cfg_accessible", MacroBuiltin::sorry}, /* Derive builtins do not need a real transcriber, but still need one. It - will however never be called since builtin derive macros get expanded + should however never be called since builtin derive macros get expanded differently, and benefit from knowing on what kind of items they are applied (struct, enums, unions) rather than receiving a list of tokens like regular builtin macros */ @@ -949,9 +949,12 @@ MacroBuiltin::sorry (Location invoc_locus, AST::MacroInvocData &invoc) } AST::Fragment -MacroBuiltin::proc_macro_builtin (Location, AST::MacroInvocData &) +MacroBuiltin::proc_macro_builtin (Location invoc_locus, + AST::MacroInvocData &invoc) { - // nothing to do! + rust_error_at (invoc_locus, "cannot invoke derive macro: %qs", + invoc.get_path ().as_string ().c_str ()); + return AST::Fragment::create_error (); } diff --git a/gcc/rust/expand/rust-macro-builtins.h b/gcc/rust/expand/rust-macro-builtins.h index 3759f62..896ccf9 100644 --- a/gcc/rust/expand/rust-macro-builtins.h +++ b/gcc/rust/expand/rust-macro-builtins.h @@ -160,8 +160,8 @@ public: static AST::Fragment sorry (Location invoc_locus, AST::MacroInvocData &invoc); - /* Builtin procedural macros do not work directly on tokens, but still need an - * empty builtin transcriber to be considered proper builtin macros */ + /* Builtin procedural macros do not work directly on tokens, but still need a + * builtin transcriber to be considered proper builtin macros */ static AST::Fragment proc_macro_builtin (Location, AST::MacroInvocData &); }; } // namespace Rust -- cgit v1.1