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:
Gino Valente 2023-11-28 18:46:09 -07:00 committed by GitHub
parent 4221f7e7e9
commit daa8bf20df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -132,9 +132,9 @@ impl WhereClauseOptions {
let custom_bounds = active_bounds(field).map(|bounds| quote!(+ #bounds));
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 {
quote!(#bevy_reflect_path::Reflect #custom_bounds)
quote!(#bevy_reflect_path::Reflect + #bevy_reflect_path::TypePath #custom_bounds)
};
(ty, bounds)

View file

@ -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() {}