Skip to content

Commit 5de21c0

Browse files
committed
maximally relax bounds for all TypePath impls
1 parent 55694a2 commit 5de21c0

File tree

10 files changed

+30
-48
lines changed

10 files changed

+30
-48
lines changed

crates/bevy_reflect/bevy_reflect_derive/src/impls/enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> TokenStream {
8484
},
8585
);
8686

87-
let type_path_impl = impl_type_path(reflect_enum.meta(), &where_clause_options);
87+
let type_path_impl = impl_type_path(reflect_enum.meta());
8888

8989
let get_type_registration_impl = reflect_enum
9090
.meta()

crates/bevy_reflect/bevy_reflect_derive/src/impls/structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> TokenStream {
9090
},
9191
);
9292

93-
let type_path_impl = impl_type_path(reflect_struct.meta(), &where_clause_options);
93+
let type_path_impl = impl_type_path(reflect_struct.meta());
9494

9595
let get_type_registration_impl = reflect_struct.get_type_registration(&where_clause_options);
9696

crates/bevy_reflect/bevy_reflect_derive/src/impls/tuple_structs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> TokenStream {
8383
},
8484
);
8585

86-
let type_path_impl = impl_type_path(reflect_struct.meta(), &where_clause_options);
86+
let type_path_impl = impl_type_path(reflect_struct.meta());
8787

8888
let (impl_generics, ty_generics, where_clause) = reflect_struct
8989
.meta()

crates/bevy_reflect/bevy_reflect_derive/src/impls/typed.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ pub(crate) enum TypedProperty {
4848
TypePath,
4949
}
5050

51-
pub(crate) fn impl_type_path(
52-
meta: &ReflectMeta,
53-
where_clause_options: &WhereClauseOptions,
54-
) -> proc_macro2::TokenStream {
51+
pub(crate) fn impl_type_path(meta: &ReflectMeta) -> proc_macro2::TokenStream {
5552
let type_path = meta.type_path();
5653
let bevy_reflect_path = meta.bevy_reflect_path();
54+
let where_clause_options = WhereClauseOptions::type_path_bounds(meta);
5755

5856
let (long_type_path, short_type_path) = if type_path.impl_is_generic() {
5957
let long_path_cell = static_type_cell(
@@ -101,7 +99,7 @@ pub(crate) fn impl_type_path(
10199
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
102100

103101
// Add Typed bound for each active field
104-
let where_reflect_clause = extend_where_clause(where_clause, where_clause_options);
102+
let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);
105103

106104
quote! {
107105
#primitive_assert

crates/bevy_reflect/bevy_reflect_derive/src/impls/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) fn impl_value(meta: &ReflectMeta) -> TokenStream {
3232
},
3333
);
3434

35-
let type_path_impl = impl_type_path(meta, &where_clause_options);
35+
let type_path_impl = impl_type_path(meta);
3636

3737
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
3838
let where_reflect_clause = extend_where_clause(where_clause, &where_clause_options);

crates/bevy_reflect/bevy_reflect_derive/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use syn::spanned::Spanned;
4141
use syn::{parse_macro_input, DeriveInput};
4242
use type_path::NamedTypePathDef;
4343
use type_uuid::TypeUuidDef;
44-
use utility::WhereClauseOptions;
4544

4645
pub(crate) static REFLECT_ATTRIBUTE_NAME: &str = "reflect";
4746
pub(crate) static REFLECT_VALUE_ATTRIBUTE_NAME: &str = "reflect_value";
@@ -220,11 +219,7 @@ pub fn derive_type_path(input: TokenStream) -> TokenStream {
220219
Err(err) => return err.into_compile_error().into(),
221220
};
222221

223-
impls::impl_type_path(
224-
derive_data.meta(),
225-
&WhereClauseOptions::type_path_bounds(derive_data.meta()),
226-
)
227-
.into()
222+
impls::impl_type_path(derive_data.meta()).into()
228223
}
229224

230225
// From https://github.com/randomPoison/type-uuid
@@ -517,7 +512,7 @@ pub fn impl_type_path(input: TokenStream) -> TokenStream {
517512

518513
let meta = ReflectMeta::new(type_path, ReflectTraits::default());
519514

520-
impls::impl_type_path(&meta, &WhereClauseOptions::type_path_bounds(&meta)).into()
515+
impls::impl_type_path(&meta).into()
521516
}
522517

523518
/// Derives `TypeUuid` for the given type. This is used internally to implement `TypeUuid` on foreign types, such as those in the std. This macro should be used in the format of `<[Generic Params]> [Type (Path)], [Uuid (String Literal)]`.

crates/bevy_reflect/src/impls/smallvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ where
148148
}
149149
}
150150

151-
impl_type_path!(::smallvec::SmallVec<T: smallvec::Array + TypePath + Send + Sync>);
151+
impl_type_path!(::smallvec::SmallVec<T: smallvec::Array>);
152152

153153
impl<T: smallvec::Array + TypePath + Send + Sync> FromReflect for SmallVec<T>
154154
where

crates/bevy_reflect/src/impls/std.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ macro_rules! impl_reflect_for_veclike {
396396
}
397397
}
398398

399-
impl_type_path!($ty where T: FromReflect);
399+
impl_type_path!($ty);
400400

401401
impl<T: FromReflect + TypePath> GetTypeRegistration for $ty {
402402
fn get_type_registration() -> TypeRegistration {
@@ -655,20 +655,12 @@ impl_reflect_for_hashmap!(::std::collections::HashMap<K, V, S>);
655655
impl_type_path!(::std::collections::hash_map::RandomState);
656656
impl_type_path!(
657657
::std::collections::HashMap<K, V, S>
658-
where
659-
K: FromReflect + Eq + Hash + ?Sized,
660-
V: FromReflect + ?Sized,
661-
S: BuildHasher + Send + Sync + 'static,
662658
);
663659

664660
impl_reflect_for_hashmap!(bevy_utils::hashbrown::HashMap<K, V, S>);
665661
impl_type_path!(::bevy_utils::hashbrown::hash_map::DefaultHashBuilder);
666662
impl_type_path!(
667663
::bevy_utils::hashbrown::HashMap<K, V, S>
668-
where
669-
K: FromReflect + Eq + Hash + ?Sized,
670-
V: FromReflect + ?Sized,
671-
S: BuildHasher + Send + Sync + 'static,
672664
);
673665

674666
impl<T: Reflect + TypePath, const N: usize> Array for [T; N] {
@@ -798,7 +790,7 @@ impl<T: Reflect + TypePath, const N: usize> Typed for [T; N] {
798790
}
799791
}
800792

801-
impl<T: Reflect + TypePath, const N: usize> TypePath for [T; N] {
793+
impl<T: TypePath, const N: usize> TypePath for [T; N] {
802794
fn type_path() -> &'static str {
803795
static CELL: GenericTypePathCell = GenericTypePathCell::new();
804796
CELL.get_or_insert::<Self, _>(|| format!("[{t}; {N}]", t = T::type_path()))
@@ -1073,7 +1065,21 @@ impl<T: FromReflect + TypePath> Typed for Option<T> {
10731065
}
10741066
}
10751067

1076-
impl_type_path!(::core::option::Option<T: FromReflect + TypePath>);
1068+
impl_type_path!(::core::option::Option<T>);
1069+
1070+
impl<T: TypePath + ?Sized> TypePath for &'static T {
1071+
fn type_path() -> &'static str {
1072+
static CELL: GenericTypePathCell = GenericTypePathCell::new();
1073+
CELL.get_or_insert::<Self, _>(|| format!("&{}", T::type_path()))
1074+
}
1075+
1076+
fn short_type_path() -> &'static str {
1077+
static CELL: GenericTypePathCell = GenericTypePathCell::new();
1078+
CELL.get_or_insert::<Self, _>(|| format!("&{}", T::short_type_path()))
1079+
}
1080+
1081+
const TYPE_PATH_ID: TypePathId = TypePathId::from_base("&").with_generics(&[T::TYPE_PATH_ID]);
1082+
}
10771083

10781084
impl Reflect for Cow<'static, str> {
10791085
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
@@ -1262,21 +1268,6 @@ impl Typed for &'static Path {
12621268
}
12631269
}
12641270

1265-
impl TypePath for &'static Path {
1266-
fn type_path() -> &'static str {
1267-
static CELL: GenericTypePathCell = GenericTypePathCell::new();
1268-
CELL.get_or_insert::<Self, _>(|| "&std::path::Path".to_owned())
1269-
}
1270-
1271-
fn short_type_path() -> &'static str {
1272-
static CELL: GenericTypePathCell = GenericTypePathCell::new();
1273-
CELL.get_or_insert::<Self, _>(|| "&Path".to_owned())
1274-
}
1275-
1276-
const TYPE_PATH_ID: TypePathId =
1277-
TypePathId::from_base("&").with_generics(&[<Path as TypePath>::TYPE_PATH_ID]);
1278-
}
1279-
12801271
impl GetTypeRegistration for &'static Path {
12811272
fn get_type_registration() -> TypeRegistration {
12821273
let mut registration = TypeRegistration::of::<Self>();
@@ -1378,10 +1369,7 @@ impl Typed for Cow<'static, Path> {
13781369
}
13791370
}
13801371

1381-
trait Cowable: ToOwned {}
1382-
impl Cowable for Path {}
1383-
impl Cowable for str {}
1384-
impl_type_path!(::alloc::borrow::Cow<'a: 'static, T: Cowable + ?Sized>);
1372+
impl_type_path!(::alloc::borrow::Cow<'a: 'static, T: ToOwned + ?Sized>);
13851373

13861374
impl FromReflect for Cow<'static, Path> {
13871375
fn from_reflect(reflect: &dyn Reflect) -> Option<Self> {

crates/bevy_reflect/src/tuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl TypePath for () {
654654

655655
macro_rules! impl_type_path_tuple {
656656
($($name:ident),+) => {
657-
impl <$($name: Reflect + TypePath),*> TypePath for ($($name,)*) {
657+
impl <$($name: TypePath),*> TypePath for ($($name,)*) {
658658
fn type_path() -> &'static str {
659659
static CELL: GenericTypePathCell = GenericTypePathCell::new();
660660
CELL.get_or_insert::<Self, _>(|| {

crates/bevy_reflect/src/type_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ impl TypePathVtable {
584584
(self.module_path)()
585585
}
586586

587+
/// See [`TypePath::TYPE_PATH_ID`].
587588
pub fn type_path_id(&self) -> TypePathId {
588589
self.type_path_id
589590
}

0 commit comments

Comments
 (0)