From 7ea40fba3c6267116e8e3497e6ce0e9af9f1ea56 Mon Sep 17 00:00:00 2001 From: Gino Valente Date: Sat, 27 Jan 2024 17:41:59 -0700 Subject: [PATCH] Add compile fail tests for custom where --- .../tests/reflect_derive/custom_where.fail.rs | 31 +++++++++++++++++++ .../reflect_derive/custom_where.fail.stderr | 11 +++++++ .../tests/reflect_derive/custom_where.pass.rs | 31 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.rs create mode 100644 crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.stderr create mode 100644 crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.pass.rs diff --git a/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.rs b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.rs new file mode 100644 index 0000000000000..f10793a5f08a9 --- /dev/null +++ b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.rs @@ -0,0 +1,31 @@ +use bevy_reflect::{Reflect, FromType}; +use std::marker::PhantomData; + +#[derive(Clone)] +struct ReflectMyTrait; + +impl FromType for ReflectMyTrait { + fn from_type() -> Self { + Self + } +} + +// Reason: where clause cannot be used with #[reflect(MyTrait)] +#[derive(Reflect)] +#[reflect(MyTrait, where)] +pub struct Foo { + value: String, + #[reflect(ignore)] + _marker: PhantomData, +} + +// Reason: where clause cannot be used with #[reflect(MyTrait)] +#[derive(Reflect)] +#[reflect(where, MyTrait)] +pub struct Bar { + value: String, + #[reflect(ignore)] + _marker: PhantomData, +} + +fn main() {} \ No newline at end of file diff --git a/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.stderr b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.stderr new file mode 100644 index 0000000000000..10916ef3541ae --- /dev/null +++ b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.fail.stderr @@ -0,0 +1,11 @@ +error: expected identifier, found keyword `where` + --> tests/reflect_derive/custom_where.fail.rs:15:20 + | +15 | #[reflect(MyTrait, where)] + | ^^^^^ + +error: unexpected token + --> tests/reflect_derive/custom_where.fail.rs:24:16 + | +24 | #[reflect(where, MyTrait)] + | ^ diff --git a/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.pass.rs b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.pass.rs new file mode 100644 index 0000000000000..f6c4eede76e74 --- /dev/null +++ b/crates/bevy_reflect_compile_fail_tests/tests/reflect_derive/custom_where.pass.rs @@ -0,0 +1,31 @@ +use bevy_reflect::{Reflect, FromType}; +use std::marker::PhantomData; + +#[derive(Clone)] +struct ReflectMyTrait; + +impl FromType for ReflectMyTrait { + fn from_type() -> Self { + Self + } +} + +#[derive(Reflect)] +#[reflect(MyTrait)] +#[reflect(where)] +pub struct Foo { + value: String, + #[reflect(ignore)] + _marker: PhantomData, +} + +#[derive(Reflect)] +#[reflect(where)] +#[reflect(MyTrait)] +pub struct Bar { + value: String, + #[reflect(ignore)] + _marker: PhantomData, +} + +fn main() {}