Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/bevy_reflect/derive/src/derive_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,17 +1238,17 @@ impl<'a> ReflectTypePath<'a> {
mut ty_generic_fn: impl FnMut(&TypeParam) -> StringExpr,
bevy_reflect_path: &Path,
) -> StringExpr {
let mut params = generics.params.iter().filter_map(|param| match param {
GenericParam::Type(type_param) => Some(ty_generic_fn(type_param)),
let mut params = generics.params.iter().map(|param| match param {
GenericParam::Type(type_param) => ty_generic_fn(type_param),
GenericParam::Const(const_param) => {
let ident = &const_param.ident;
let ty = &const_param.ty;

Some(StringExpr::Owned(quote! {
StringExpr::Owned(quote! {
<#ty as #bevy_reflect_path::__macro_exports::alloc_utils::ToString>::to_string(&#ident)
}))
})
}
GenericParam::Lifetime(_) => None,
GenericParam::Lifetime(_) => StringExpr::from_str("'_"),
});

params
Expand All @@ -1269,7 +1269,7 @@ impl<'a> ReflectTypePath<'a> {
let ident = self.type_ident().unwrap();
let module_path = self.module_path().unwrap();

if self.impl_is_generic() {
if !generics.params.is_empty() {
let generics = ReflectTypePath::reduce_generics(
generics,
|TypeParam { ident, .. }| {
Expand Down Expand Up @@ -1307,7 +1307,7 @@ impl<'a> ReflectTypePath<'a> {
Self::External { generics, .. } | Self::Internal { generics, .. } => {
let ident = self.type_ident().unwrap();

if self.impl_is_generic() {
if !generics.params.is_empty() {
let generics = ReflectTypePath::reduce_generics(
generics,
|TypeParam { ident, .. }| {
Expand Down
13 changes: 12 additions & 1 deletion crates/bevy_reflect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,18 @@ mod tests {
(Type,) => "(Long,)", "(Short,)",
(Type, Type) => "(Long, Long)", "(Short, Short)",
(Type, Type, Type) => "(Long, Long, Long)", "(Short, Short, Short)",
Cow<'static, Type> => "alloc::borrow::Cow<Long>", "Cow<Short>",
Cow<'static, Type> => "alloc::borrow::Cow<'_, Long>", "Cow<'_, Short>",
}

#[expect(
dead_code,
reason = "field 0 carries the lifetime which is used in the type path"
)]
#[derive(TypePath)]
struct WithLifetime<'a>(&'a ());

assert_type_paths! {
WithLifetime<'static> => "bevy_reflect::tests::WithLifetime<'_>", "WithLifetime<'_>",
}
}

Expand Down
Loading