mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix nested generics in Reflect derive (#10791)
# Objective > Issue raised on [Discord](https://discord.com/channels/691052431525675048/1002362493634629796/1179182488787103776) Currently the following code fails due to a missing `TypePath` bound: ```rust #[derive(Reflect)] struct Foo<T>(T); #[derive(Reflect)] struct Bar<T>(Foo<T>); #[derive(Reflect)] struct Baz<T>(Bar<Foo<T>>); ``` ## Solution Add `TypePath` to the per-field bounds instead of _just_ the generic type parameter bounds. ### Related Work It should be noted that #9046 would help make these kinds of issues easier to work around and/or avoid entirely. --- ## Changelog - Fixes missing `TypePath` requirement when deriving `Reflect` on nested generics
This commit is contained in:
parent
4221f7e7e9
commit
daa8bf20df
2 changed files with 18 additions and 2 deletions
|
@ -132,9 +132,9 @@ impl WhereClauseOptions {
|
||||||
let custom_bounds = active_bounds(field).map(|bounds| quote!(+ #bounds));
|
let custom_bounds = active_bounds(field).map(|bounds| quote!(+ #bounds));
|
||||||
|
|
||||||
let bounds = if is_from_reflect {
|
let bounds = if is_from_reflect {
|
||||||
quote!(#bevy_reflect_path::FromReflect #custom_bounds)
|
quote!(#bevy_reflect_path::FromReflect + #bevy_reflect_path::TypePath #custom_bounds)
|
||||||
} else {
|
} else {
|
||||||
quote!(#bevy_reflect_path::Reflect #custom_bounds)
|
quote!(#bevy_reflect_path::Reflect + #bevy_reflect_path::TypePath #custom_bounds)
|
||||||
};
|
};
|
||||||
|
|
||||||
(ty, bounds)
|
(ty, bounds)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
use bevy_reflect::Reflect;
|
||||||
|
|
||||||
|
mod nested_generics {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Reflect)]
|
||||||
|
struct Foo<T>(T);
|
||||||
|
|
||||||
|
#[derive(Reflect)]
|
||||||
|
struct Bar<T>(Foo<T>);
|
||||||
|
|
||||||
|
#[derive(Reflect)]
|
||||||
|
struct Baz<T>(Bar<Foo<T>>);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in a new issue