diff --git a/crates/bevy_utils/Cargo.toml b/crates/bevy_utils/Cargo.toml index 4e74e6ea94..447c9966f4 100644 --- a/crates/bevy_utils/Cargo.toml +++ b/crates/bevy_utils/Cargo.toml @@ -18,7 +18,7 @@ parallel = ["bevy_platform/std", "dep:thread_local"] std = ["disqualified/alloc"] -debug = [] +debug = ["bevy_platform/alloc"] [dependencies] bevy_platform = { path = "../bevy_platform", version = "0.17.0-dev", default-features = false } diff --git a/crates/bevy_utils/src/debug_info.rs b/crates/bevy_utils/src/debug_info.rs index c79c5ebe60..84232c9d3d 100644 --- a/crates/bevy_utils/src/debug_info.rs +++ b/crates/bevy_utils/src/debug_info.rs @@ -1,4 +1,7 @@ -use alloc::{borrow::Cow, fmt, string::String}; +use crate::cfg; +cfg::alloc! { + use alloc::{borrow::Cow, fmt, string::String}; +} #[cfg(feature = "debug")] use core::any::type_name; use disqualified::ShortName; @@ -16,14 +19,16 @@ pub struct DebugName { name: Cow<'static, str>, } -impl fmt::Display for DebugName { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - #[cfg(feature = "debug")] - f.write_str(self.name.as_ref())?; - #[cfg(not(feature = "debug"))] - f.write_str(FEATURE_DISABLED)?; +cfg::alloc! { + impl fmt::Display for DebugName { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + #[cfg(feature = "debug")] + f.write_str(self.name.as_ref())?; + #[cfg(not(feature = "debug"))] + f.write_str(FEATURE_DISABLED)?; - Ok(()) + Ok(()) + } } } @@ -39,14 +44,16 @@ impl DebugName { } } - /// Create a new `DebugName` from a `String` - /// - /// The value will be ignored if the `debug` feature is not enabled - #[cfg_attr(not(feature = "debug"), expect(unused_variables))] - pub fn owned(value: String) -> Self { - DebugName { - #[cfg(feature = "debug")] - name: Cow::Owned(value), + cfg::alloc! { + /// Create a new `DebugName` from a `String` + /// + /// The value will be ignored if the `debug` feature is not enabled + #[cfg_attr(not(feature = "debug"), expect(unused_variables))] + pub fn owned(value: String) -> Self { + DebugName { + #[cfg(feature = "debug")] + name: Cow::Owned(value), + } } } @@ -79,19 +86,21 @@ impl DebugName { } } -impl From> for DebugName { - #[cfg_attr(not(feature = "debug"), expect(unused_variables))] - fn from(value: Cow<'static, str>) -> Self { - Self { - #[cfg(feature = "debug")] - name: value, +cfg::alloc! { + impl From> for DebugName { + #[cfg_attr(not(feature = "debug"), expect(unused_variables))] + fn from(value: Cow<'static, str>) -> Self { + Self { + #[cfg(feature = "debug")] + name: value, + } } } -} -impl From for DebugName { - fn from(value: String) -> Self { - Self::owned(value) + impl From for DebugName { + fn from(value: String) -> Self { + Self::owned(value) + } } }