[gcc r14-7647] gccrs: Add error message when derive macro is invoked
Arthur Cohen
cohenarthur@gcc.gnu.org
Tue Jan 16 17:50:20 GMT 2024
https://gcc.gnu.org/g:e50a99a1aa386427050662a52bbedee18d895fc9
commit r14-7647-ge50a99a1aa386427050662a52bbedee18d895fc9
Author: Owen Avery <powerboat9.gamer@gmail.com>
Date: Mon Jun 5 10:41:43 2023 -0400
gccrs: 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 <powerboat9.gamer@gmail.com>
Diff:
---
gcc/rust/expand/rust-macro-builtins.cc | 9 ++++++---
gcc/rust/expand/rust-macro-builtins.h | 4 ++--
gcc/testsuite/rust/compile/derive_macro8.rs | 9 +++++++++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc
index 33b813c4594..363819b35c5 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 3ad10a33920..87b6a1ed9da 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
diff --git a/gcc/testsuite/rust/compile/derive_macro8.rs b/gcc/testsuite/rust/compile/derive_macro8.rs
new file mode 100644
index 00000000000..ba7e7103631
--- /dev/null
+++ b/gcc/testsuite/rust/compile/derive_macro8.rs
@@ -0,0 +1,9 @@
+#![feature(rustc_attrs)]
+#![feature(decl_macro)]
+
+#[rustc_builtin_macro]
+pub macro Copy($i:item) { /* builtin */ }
+
+pub fn foo() {
+ Copy!(); // { dg-error "cannot invoke derive macro" }
+}
More information about the Gcc-cvs
mailing list