From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 6B13938582BC; Tue, 16 Jan 2024 18:02:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B13938582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705428164; bh=gveRv5MoD0rkegvmARU0HcJuiVtX75+Gf9HOQ4SW4lk=; h=From:To:Subject:Date:From; b=qJs73bJTYbsZAA8OMi5WPjA4NHANraU1PbfHbY8FbAAugVaK03CcAKvSNkUh74QtK H6CEzRLXftKBNcFpJPvKVR8iCGnLMDRQF/Gxc4CvFqZn5C7StJhhXIaHv3JeSlkHpR sMjsHPm5O0kcg6JCHjQkBfWWgIC/TpaSKQrLtV4Q= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-7836] gccrs: Add tests for non function proc_macro_derive X-Act-Checkin: gcc X-Git-Author: Pierre-Emmanuel Patry X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 3c1cc1190a23f6dc9c5028e1b92e7bbb85651ac3 X-Git-Newrev: e58650e6df390e71e7ce880c6bc895a4c4930e25 Message-Id: <20240116180244.6B13938582BC@sourceware.org> Date: Tue, 16 Jan 2024 18:02:44 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e58650e6df390e71e7ce880c6bc895a4c4930e25 commit r14-7836-ge58650e6df390e71e7ce880c6bc895a4c4930e25 Author: Pierre-Emmanuel Patry 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 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" {}