diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-21 14:18:12 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-07-27 09:40:30 +0000 |
commit | 9a906fea9e4230c625ba5fe169f447450ab5f4c9 (patch) | |
tree | 428c4987614906882443405aafc2c2ef11759637 | |
parent | 456d1f0a04c9a76acba8443fda23ec58081db874 (diff) | |
download | gcc-9a906fea9e4230c625ba5fe169f447450ab5f4c9.zip gcc-9a906fea9e4230c625ba5fe169f447450ab5f4c9.tar.gz gcc-9a906fea9e4230c625ba5fe169f447450ab5f4c9.tar.bz2 |
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>
-rw-r--r-- | gcc/testsuite/rust/compile/proc_macro_derive_non_function.rs | 60 |
1 files changed, 60 insertions, 0 deletions
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 0000000..7cb4c0b --- /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" {} |