Skip to content

Commit

Permalink
Fix compile fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Apr 21, 2023
1 parent 90b01bb commit f40347e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy_reflect::Reflect;
use bevy_reflect::{GetField, Reflect, Struct};

#[derive(Reflect)]
struct Foo<T> {
Expand All @@ -9,7 +9,7 @@ struct Foo<T> {
struct NoReflect(f32);

fn main() {
let mut foo: Box<dyn Reflect> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
// foo doesn't implement Reflect because NoReflect doesn't implement Reflect
foo.get_field::<NoReflect>("a").unwrap();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
error[E0599]: no method named `get_field` found for struct `Box<(dyn Reflect + 'static)>` in the current scope
--> tests/reflect_derive/generics.fail.rs:14:9
|
14 | foo.get_field::<NoReflect>("a").unwrap();
| ^^^^^^^^^ method not found in `Box<dyn Reflect>`

error[E0277]: the trait bound `NoReflect: Reflect` is not satisfied
--> tests/reflect_derive/generics.fail.rs:12:37
--> tests/reflect_derive/generics.fail.rs:14:21
|
14 | foo.get_field::<NoReflect>("a").unwrap();
| ^^^^^^^^^ the trait `Reflect` is not implemented for `NoReflect`
|
= help: the following other types implement trait `Reflect`:
&'static Path
()
(A, B)
(A, B, C)
(A, B, C, D)
(A, B, C, D, E)
(A, B, C, D, E, F)
(A, B, C, D, E, F, G)
and $N others
note: required by a bound in `bevy_reflect::GetField::get_field`
--> /Users/ginovalente/Projects/Git/rust/bevy/crates/bevy_reflect/src/struct_trait.rs:243:21
|
243 | fn get_field<T: Reflect>(&self, name: &str) -> Option<&T>;
| ^^^^^^^ required by this bound in `GetField::get_field`

error[E0277]: the trait bound `NoReflect: GetTypeRegistration` is not satisfied
--> tests/reflect_derive/generics.fail.rs:12:36
|
12 | let mut foo: Box<dyn Reflect> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Reflect` is not implemented for `NoReflect`
12 | let mut foo: Box<dyn Struct> = Box::new(Foo::<NoReflect> { a: NoReflect(42.0) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `GetTypeRegistration` is not implemented for `NoReflect`
|
= help: the following other types implement trait `Reflect`:
= help: the following other types implement trait `GetTypeRegistration`:
&'static Path
()
(A, B)
Expand All @@ -20,12 +36,12 @@ error[E0277]: the trait bound `NoReflect: Reflect` is not satisfied
(A, B, C, D, E, F)
(A, B, C, D, E, F, G)
and $N others
note: required for `Foo<NoReflect>` to implement `Reflect`
note: required for `Foo<NoReflect>` to implement `bevy_reflect::Struct`
--> tests/reflect_derive/generics.fail.rs:3:10
|
3 | #[derive(Reflect)]
| ^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
4 | struct Foo<T> {
| ^^^^^^
= note: required for the cast from `Foo<NoReflect>` to the object type `dyn Reflect`
= note: required for the cast from `Foo<NoReflect>` to the object type `dyn bevy_reflect::Struct`
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit f40347e

Please sign in to comment.