Skip to content

Commit 33bed5d

Browse files
authored
bevy_reflect: remove unnecessary const _ around TypePath impl (#19902)
# Objective Derived `TypePath` impls have a `const _` block in order to hold a `use alloc::string::ToString` import. But that import is useless. Avoiding it helps with #19873. ## Solution Remove the `use` and `const _`. ## Testing I used cargo expand to confirm the `const _ ` is no longer produced. `-Zmacro-stats` output tells me this reduces the size of the `Reflect` code produced for `bevy_ui` from 1_880_486 bytes to 1_859_634 bytes, a 1.1% drop.
1 parent d83bae4 commit 33bed5d

File tree

1 file changed

+16
-23
lines changed
  • crates/bevy_reflect/derive/src/impls

1 file changed

+16
-23
lines changed

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,27 @@ pub(crate) fn impl_type_path(meta: &ReflectMeta) -> TokenStream {
106106
quote! {
107107
#primitive_assert
108108

109-
// To ensure alloc is available, but also prevent its name from clashing, we place the implementation inside an anonymous constant
110-
const _: () = {
111-
extern crate alloc;
112-
113-
use alloc::string::ToString;
114-
115-
impl #impl_generics #bevy_reflect_path::TypePath for #type_path #ty_generics #where_reflect_clause {
116-
fn type_path() -> &'static str {
117-
#long_type_path
118-
}
109+
impl #impl_generics #bevy_reflect_path::TypePath for #type_path #ty_generics #where_reflect_clause {
110+
fn type_path() -> &'static str {
111+
#long_type_path
112+
}
119113

120-
fn short_type_path() -> &'static str {
121-
#short_type_path
122-
}
114+
fn short_type_path() -> &'static str {
115+
#short_type_path
116+
}
123117

124-
fn type_ident() -> Option<&'static str> {
125-
#type_ident
126-
}
118+
fn type_ident() -> Option<&'static str> {
119+
#type_ident
120+
}
127121

128-
fn crate_name() -> Option<&'static str> {
129-
#crate_name
130-
}
122+
fn crate_name() -> Option<&'static str> {
123+
#crate_name
124+
}
131125

132-
fn module_path() -> Option<&'static str> {
133-
#module_path
134-
}
126+
fn module_path() -> Option<&'static str> {
127+
#module_path
135128
}
136-
};
129+
}
137130
}
138131
}
139132

0 commit comments

Comments
 (0)