public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-7836] gccrs: Add tests for non function proc_macro_derive
Date: Tue, 16 Jan 2024 18:02:44 +0000 (GMT)	[thread overview]
Message-ID: <20240116180244.6B13938582BC@sourceware.org> (raw)

https://gcc.gnu.org/g:e58650e6df390e71e7ce880c6bc895a4c4930e25

commit r14-7836-ge58650e6df390e71e7ce880c6bc895a4c4930e25
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Fri Jul 21 14:18:12 2023 +0200

    gccrs: Add tests for non function proc_macro_derive
    
    Add a bunch of test cases to avoid regressions on proc_macro_derive
    attribute errors when placed on any non function item.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/proc_macro_derive_non_function.rs: New test.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 .../rust/compile/proc_macro_derive_non_function.rs | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/gcc/testsuite/rust/compile/proc_macro_derive_non_function.rs b/gcc/testsuite/rust/compile/proc_macro_derive_non_function.rs
new file mode 100644
index 00000000000..7cb4c0b883c
--- /dev/null
+++ b/gcc/testsuite/rust/compile/proc_macro_derive_non_function.rs
@@ -0,0 +1,60 @@
+// { dg-additional-options "-frust-crate-type=proc-macro" }
+
+trait ToDerive {}
+
+mod inner {
+    struct InnerStruct;
+}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+type AliasedType = inner::InnerStruct;
+
+// { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" "" { target *-*-* } .+1 }
+#[proc_macro_derive(ToDerive)]
+use inner::InnerStruct;
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+struct MyStruct;
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+struct MyCurlyStruct {
+    member: usize,
+}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+struct MyTupleStruct(usize);
+
+#[proc_macro_derive(ToDerive)]
+// { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" "" { target *-*-* } .-1 }
+extern crate my_extern_crate; // { dg-error "unknown crate .my_extern_crate." }
+                              // { dg-error "failed to locate crate .my_extern_crate." "" { target *-*-* } .-1 }
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+mod my_module {}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+enum MyEnum {}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+union MyUnion {
+    f1: u32,
+    f2: f32,
+}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+const MY_CONST_STR: &str = "my_string";
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+static MY_STATIC_USIZE: usize = 10;
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+trait MyTrait {}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+impl MyStruct {}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+impl MyTrait for MyStruct {}
+
+#[proc_macro_derive(ToDerive)] // { dg-error "the .#.proc_macro_derive.. attribute may only be used on bare functions" }
+extern "C" {}

                 reply	other threads:[~2024-01-16 18:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116180244.6B13938582BC@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).