Skip to content

Commit

Permalink
Add compile fail tests for custom where
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Jan 28, 2024
1 parent be18a8f commit 7ea40fb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use bevy_reflect::{Reflect, FromType};
use std::marker::PhantomData;

#[derive(Clone)]
struct ReflectMyTrait;

impl<T> FromType<T> for ReflectMyTrait {
fn from_type() -> Self {
Self
}
}

// Reason: where clause cannot be used with #[reflect(MyTrait)]
#[derive(Reflect)]
#[reflect(MyTrait, where)]
pub struct Foo<T> {
value: String,
#[reflect(ignore)]
_marker: PhantomData<T>,
}

// Reason: where clause cannot be used with #[reflect(MyTrait)]
#[derive(Reflect)]
#[reflect(where, MyTrait)]
pub struct Bar<T> {
value: String,
#[reflect(ignore)]
_marker: PhantomData<T>,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -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)]
| ^
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use bevy_reflect::{Reflect, FromType};
use std::marker::PhantomData;

#[derive(Clone)]
struct ReflectMyTrait;

impl<T> FromType<T> for ReflectMyTrait {
fn from_type() -> Self {
Self
}
}

#[derive(Reflect)]
#[reflect(MyTrait)]
#[reflect(where)]
pub struct Foo<T> {
value: String,
#[reflect(ignore)]
_marker: PhantomData<T>,
}

#[derive(Reflect)]
#[reflect(where)]
#[reflect(MyTrait)]
pub struct Bar<T> {
value: String,
#[reflect(ignore)]
_marker: PhantomData<T>,
}

fn main() {}

0 comments on commit 7ea40fb

Please sign in to comment.