aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2023-06-05 10:41:43 -0400
committerCohenArthur <arthur.cohen@embecosm.com>2023-06-07 08:31:28 +0000
commit25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3 (patch)
treeba48eaf0e4682b7958d74b437023fbf1a866d69d
parent12d79b13fc314b349a727b2ab15d4d06270f3496 (diff)
downloadgcc-25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3.zip
gcc-25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3.tar.gz
gcc-25b40ba2e03c4ff030adb7ce8ce00e5315c46cb3.tar.bz2
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>
-rw-r--r--gcc/rust/expand/rust-macro-builtins.cc9
-rw-r--r--gcc/rust/expand/rust-macro-builtins.h4
-rw-r--r--gcc/testsuite/rust/compile/derive_macro8.rs9
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 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
diff --git a/gcc/testsuite/rust/compile/derive_macro8.rs b/gcc/testsuite/rust/compile/derive_macro8.rs
new file mode 100644
index 0000000..ba7e710
--- /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" }
+}