diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index b9e2902961..48aa26ec51 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -12,10 +12,13 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! This crate is about everything concerning the highest-level, application layer of a Bevy app. +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; mod app; diff --git a/crates/bevy_app/src/plugin_group.rs b/crates/bevy_app/src/plugin_group.rs index 312b94ad91..49d05f3229 100644 --- a/crates/bevy_app/src/plugin_group.rs +++ b/crates/bevy_app/src/plugin_group.rs @@ -554,6 +554,7 @@ impl PluginGroup for NoopPluginGroup { #[cfg(test)] mod tests { + use alloc::vec; use core::{any::TypeId, fmt::Debug}; use super::PluginGroupBuilder; diff --git a/crates/bevy_color/src/lib.rs b/crates/bevy_color/src/lib.rs index 4a4a9596d5..e80e68bb9e 100644 --- a/crates/bevy_color/src/lib.rs +++ b/crates/bevy_color/src/lib.rs @@ -4,7 +4,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! Representations of colors in various color spaces. //! @@ -90,6 +90,9 @@ //! println!("Hsla: {:?}", hsla); //! ``` +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "alloc")] extern crate alloc; diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 14d80cf9ab..9a0403f2d9 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -1643,6 +1643,7 @@ fn sorted_remove(source: &mut Vec, remove: &[T]) { mod tests { use crate as bevy_ecs; use crate::{component::ComponentId, prelude::*, world::DeferredWorld}; + use alloc::vec; #[derive(Component)] struct A; diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index 4a326cc955..2b51c1f937 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -671,6 +671,7 @@ mod tests { entity::EntityCloneBuilder, world::{DeferredWorld, World}, }; + use alloc::vec::Vec; use bevy_ecs_macros::require; use bevy_ptr::OwningPtr; use core::alloc::Layout; @@ -679,6 +680,7 @@ mod tests { mod reflect { use super::*; use crate::reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld}; + use alloc::vec; use bevy_reflect::{std_traits::ReflectDefault, FromType, Reflect, ReflectFromPtr}; #[test] diff --git a/crates/bevy_ecs/src/entity/entity_set.rs b/crates/bevy_ecs/src/entity/entity_set.rs index 34e48551fd..be8ac88d04 100644 --- a/crates/bevy_ecs/src/entity/entity_set.rs +++ b/crates/bevy_ecs/src/entity/entity_set.rs @@ -135,6 +135,7 @@ unsafe impl TrustedEntityBorrow for Arc {} /// [`into_iter()`]: IntoIterator::into_iter /// [`iter_many_unique`]: crate::system::Query::iter_many_unique /// [`iter_many_unique_mut`]: crate::system::Query::iter_many_unique_mut +/// [`Vec`]: alloc::vec::Vec pub trait EntitySet: IntoIterator {} impl> EntitySet for T {} @@ -379,6 +380,8 @@ impl + Debug> Debug for UniqueEntityIter< #[cfg(test)] mod tests { + use alloc::{vec, vec::Vec}; + #[allow(unused_imports)] use crate::prelude::{Schedule, World}; diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 8d5489add0..1a177e7ff5 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -74,7 +74,7 @@ use core::{fmt, hash::Hash, mem, num::NonZero}; use log::warn; #[cfg(feature = "track_location")] -use core::panic::Location; +use {alloc::format, core::panic::Location}; #[cfg(feature = "serialize")] use serde::{Deserialize, Serialize}; @@ -1065,6 +1065,7 @@ impl EntityLocation { #[cfg(test)] mod tests { use super::*; + use alloc::format; #[test] fn entity_niche_optimization() { diff --git a/crates/bevy_ecs/src/entity/visit_entities.rs b/crates/bevy_ecs/src/entity/visit_entities.rs index abce76853d..a9f5e8dcbd 100644 --- a/crates/bevy_ecs/src/entity/visit_entities.rs +++ b/crates/bevy_ecs/src/entity/visit_entities.rs @@ -61,6 +61,7 @@ mod tests { entity::{EntityHashMap, MapEntities, SceneEntityMapper}, world::World, }; + use alloc::{string::String, vec, vec::Vec}; use bevy_utils::HashSet; use super::*; diff --git a/crates/bevy_ecs/src/event/mod.rs b/crates/bevy_ecs/src/event/mod.rs index 46b04c8a18..1dbcf1ba0c 100644 --- a/crates/bevy_ecs/src/event/mod.rs +++ b/crates/bevy_ecs/src/event/mod.rs @@ -32,6 +32,7 @@ pub use writer::EventWriter; #[cfg(test)] mod tests { use crate as bevy_ecs; + use alloc::{vec, vec::Vec}; use bevy_ecs::{event::*, system::assert_is_read_only_system}; use bevy_ecs_macros::Event; diff --git a/crates/bevy_ecs/src/intern.rs b/crates/bevy_ecs/src/intern.rs index e606b0d546..18e866e87d 100644 --- a/crates/bevy_ecs/src/intern.rs +++ b/crates/bevy_ecs/src/intern.rs @@ -180,6 +180,7 @@ impl Default for Interner { #[cfg(test)] mod tests { + use alloc::{boxed::Box, string::ToString}; use bevy_utils::FixedHasher; use core::hash::{BuildHasher, Hash, Hasher}; diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index ab949045ef..ef5db63779 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -16,7 +16,10 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; #[cfg(target_pointer_width = "16")] compile_error!("bevy_ecs cannot safely compile for a 16-bit platform."); @@ -120,7 +123,12 @@ mod tests { system::Resource, world::{EntityMut, EntityRef, Mut, World}, }; - use alloc::{sync::Arc, vec}; + use alloc::{ + string::{String, ToString}, + sync::Arc, + vec, + vec::Vec, + }; use bevy_ecs_macros::{VisitEntities, VisitEntitiesMut}; use bevy_tasks::{ComputeTaskPool, TaskPool}; use bevy_utils::HashSet; diff --git a/crates/bevy_ecs/src/name.rs b/crates/bevy_ecs/src/name.rs index 4697bb50e9..05bc0e8c9c 100644 --- a/crates/bevy_ecs/src/name.rs +++ b/crates/bevy_ecs/src/name.rs @@ -264,6 +264,7 @@ impl<'de> Visitor<'de> for NameVisitor { mod tests { use super::*; use crate::world::World; + use alloc::string::ToString; #[test] fn test_display_of_debug_name() { diff --git a/crates/bevy_ecs/src/observer/mod.rs b/crates/bevy_ecs/src/observer/mod.rs index 2f69097348..8194c1e04e 100644 --- a/crates/bevy_ecs/src/observer/mod.rs +++ b/crates/bevy_ecs/src/observer/mod.rs @@ -744,7 +744,7 @@ impl World { #[cfg(test)] mod tests { - use alloc::vec; + use alloc::{vec, vec::Vec}; use bevy_ptr::OwningPtr; use bevy_utils::HashMap; diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index a526d4765e..be97d19c68 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -1338,6 +1338,7 @@ mod tests { use crate::query::{ access::AccessFilters, Access, AccessConflicts, FilteredAccess, FilteredAccessSet, }; + use alloc::vec; use core::marker::PhantomData; use fixedbitset::FixedBitSet; diff --git a/crates/bevy_ecs/src/query/builder.rs b/crates/bevy_ecs/src/query/builder.rs index aeb328afe6..55473cf050 100644 --- a/crates/bevy_ecs/src/query/builder.rs +++ b/crates/bevy_ecs/src/query/builder.rs @@ -278,6 +278,7 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> { mod tests { use crate as bevy_ecs; use crate::{prelude::*, world::FilteredEntityRef}; + use std::dbg; #[derive(Component, PartialEq, Debug)] struct A(usize); diff --git a/crates/bevy_ecs/src/query/error.rs b/crates/bevy_ecs/src/query/error.rs index 9746471c66..b2dafc64a9 100644 --- a/crates/bevy_ecs/src/query/error.rs +++ b/crates/bevy_ecs/src/query/error.rs @@ -119,6 +119,7 @@ pub enum QuerySingleError { mod test { use crate as bevy_ecs; use crate::prelude::World; + use alloc::format; use bevy_ecs_macros::Component; #[test] diff --git a/crates/bevy_ecs/src/query/iter.rs b/crates/bevy_ecs/src/query/iter.rs index c7303382f6..0f4cfe2bed 100644 --- a/crates/bevy_ecs/src/query/iter.rs +++ b/crates/bevy_ecs/src/query/iter.rs @@ -2950,6 +2950,9 @@ impl Ord for NeutralOrd { #[cfg(test)] mod tests { + use alloc::vec::Vec; + use std::println; + #[allow(unused_imports)] use crate::component::Component; #[allow(unused_imports)] diff --git a/crates/bevy_ecs/src/query/mod.rs b/crates/bevy_ecs/src/query/mod.rs index c6c1383ceb..720489d6d1 100644 --- a/crates/bevy_ecs/src/query/mod.rs +++ b/crates/bevy_ecs/src/query/mod.rs @@ -117,9 +117,10 @@ mod tests { system::{assert_is_system, IntoSystem, Query, System, SystemState}, world::{unsafe_world_cell::UnsafeWorldCell, World}, }; + use alloc::{vec, vec::Vec}; use bevy_ecs_macros::QueryFilter; use core::{any::type_name, fmt::Debug, hash::Hash}; - use std::collections::HashSet; + use std::{collections::HashSet, println}; #[derive(Component, Debug, Hash, Eq, PartialEq, Clone, Copy, PartialOrd, Ord)] struct A(usize); diff --git a/crates/bevy_ecs/src/query/state.rs b/crates/bevy_ecs/src/query/state.rs index 36d82772d4..b6025e5d7d 100644 --- a/crates/bevy_ecs/src/query/state.rs +++ b/crates/bevy_ecs/src/query/state.rs @@ -1883,6 +1883,7 @@ mod tests { use crate::{ component::Component, prelude::*, query::QueryEntityError, world::FilteredEntityRef, }; + use alloc::vec::Vec; #[test] fn get_many_unchecked_manual_uniqueness() { diff --git a/crates/bevy_ecs/src/reflect/entity_commands.rs b/crates/bevy_ecs/src/reflect/entity_commands.rs index 0d77e4b4b8..a6346b3a69 100644 --- a/crates/bevy_ecs/src/reflect/entity_commands.rs +++ b/crates/bevy_ecs/src/reflect/entity_commands.rs @@ -403,6 +403,7 @@ mod tests { system::{Commands, SystemState}, world::World, }; + use alloc::{borrow::ToOwned, boxed::Box}; use bevy_ecs_macros::Resource; use bevy_reflect::{PartialReflect, Reflect, TypeRegistry}; diff --git a/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs b/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs index 87f58a52de..1185931fd6 100644 --- a/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs +++ b/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs @@ -4,7 +4,10 @@ use bevy_utils::{default, syncunsafecell::SyncUnsafeCell}; use concurrent_queue::ConcurrentQueue; use core::{any::Any, panic::AssertUnwindSafe}; use fixedbitset::FixedBitSet; -use std::sync::{Mutex, MutexGuard}; +use std::{ + eprintln, + sync::{Mutex, MutexGuard}, +}; #[cfg(feature = "trace")] use tracing::{info_span, Span}; diff --git a/crates/bevy_ecs/src/schedule/executor/simple.rs b/crates/bevy_ecs/src/schedule/executor/simple.rs index 91a3d83b3d..122414f45e 100644 --- a/crates/bevy_ecs/src/schedule/executor/simple.rs +++ b/crates/bevy_ecs/src/schedule/executor/simple.rs @@ -1,8 +1,12 @@ use core::panic::AssertUnwindSafe; use fixedbitset::FixedBitSet; + #[cfg(feature = "trace")] use tracing::info_span; +#[cfg(feature = "std")] +use std::eprintln; + use crate::{ schedule::{ executor::is_apply_deferred, BoxedCondition, ExecutorKind, SystemExecutor, SystemSchedule, diff --git a/crates/bevy_ecs/src/schedule/executor/single_threaded.rs b/crates/bevy_ecs/src/schedule/executor/single_threaded.rs index d92519ee63..b42b419e9f 100644 --- a/crates/bevy_ecs/src/schedule/executor/single_threaded.rs +++ b/crates/bevy_ecs/src/schedule/executor/single_threaded.rs @@ -1,8 +1,12 @@ use core::panic::AssertUnwindSafe; use fixedbitset::FixedBitSet; + #[cfg(feature = "trace")] use tracing::info_span; +#[cfg(feature = "std")] +use std::eprintln; + use crate::{ schedule::{is_apply_deferred, BoxedCondition, ExecutorKind, SystemExecutor, SystemSchedule}, world::World, diff --git a/crates/bevy_ecs/src/schedule/graph/graph_map.rs b/crates/bevy_ecs/src/schedule/graph/graph_map.rs index 91ced56e5d..e24926499f 100644 --- a/crates/bevy_ecs/src/schedule/graph/graph_map.rs +++ b/crates/bevy_ecs/src/schedule/graph/graph_map.rs @@ -393,6 +393,7 @@ impl CompactNodeIdPair { #[cfg(test)] mod tests { use super::*; + use alloc::vec; /// The `Graph` type _must_ preserve the order that nodes are inserted in if /// no removals occur. Removals are permitted to swap the latest node into the diff --git a/crates/bevy_ecs/src/schedule/mod.rs b/crates/bevy_ecs/src/schedule/mod.rs index dc2a907949..4a5b5a0991 100644 --- a/crates/bevy_ecs/src/schedule/mod.rs +++ b/crates/bevy_ecs/src/schedule/mod.rs @@ -17,6 +17,7 @@ pub use self::graph::NodeId; #[cfg(test)] mod tests { use super::*; + use alloc::{string::ToString, vec, vec::Vec}; use core::sync::atomic::{AtomicU32, Ordering}; pub use crate as bevy_ecs; diff --git a/crates/bevy_ecs/src/schedule/stepping.rs b/crates/bevy_ecs/src/schedule/stepping.rs index df71139db4..867fb5f987 100644 --- a/crates/bevy_ecs/src/schedule/stepping.rs +++ b/crates/bevy_ecs/src/schedule/stepping.rs @@ -823,6 +823,8 @@ impl ScheduleState { mod tests { use super::*; use crate::{prelude::*, schedule::ScheduleLabel}; + use alloc::{format, vec}; + use std::println; pub use crate as bevy_ecs; diff --git a/crates/bevy_ecs/src/storage/blob_array.rs b/crates/bevy_ecs/src/storage/blob_array.rs index c508b78c98..86315386a8 100644 --- a/crates/bevy_ecs/src/storage/blob_array.rs +++ b/crates/bevy_ecs/src/storage/blob_array.rs @@ -77,6 +77,8 @@ impl BlobArray { /// # Safety /// - The element at index `index` is safe to access. /// (If the safety requirements of every method that has been used on `Self` have been fulfilled, the caller just needs to ensure that `index` < `len`) + /// + /// [`Vec::len`]: alloc::vec::Vec::len #[inline] pub unsafe fn get_unchecked(&self, index: usize) -> Ptr<'_> { #[cfg(debug_assertions)] @@ -98,6 +100,8 @@ impl BlobArray { /// # Safety /// - The element with at index `index` is safe to access. /// (If the safety requirements of every method that has been used on `Self` have been fulfilled, the caller just needs to ensure that `index` < `len`) + /// + /// [`Vec::len`]: alloc::vec::Vec::len #[inline] pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> PtrMut<'_> { #[cfg(debug_assertions)] @@ -134,6 +138,8 @@ impl BlobArray { /// # Safety /// - The type `T` must be the type of the items in this [`BlobArray`]. /// - `slice_len` <= `len` + /// + /// [`Vec::len`]: alloc::vec::Vec::len pub unsafe fn get_sub_slice(&self, slice_len: usize) -> &[UnsafeCell] { #[cfg(debug_assertions)] debug_assert!(slice_len <= self.capacity); @@ -151,6 +157,8 @@ impl BlobArray { /// # Safety /// - For every element with index `i`, if `i` < `len`: It must be safe to call [`Self::get_unchecked_mut`] with `i`. /// (If the safety requirements of every method that has been used on `Self` have been fulfilled, the caller just needs to ensure that `len` is correct.) + /// + /// [`Vec::clear`]: alloc::vec::Vec::clear pub unsafe fn clear(&mut self, len: usize) { #[cfg(debug_assertions)] debug_assert!(self.capacity >= len); diff --git a/crates/bevy_ecs/src/storage/blob_vec.rs b/crates/bevy_ecs/src/storage/blob_vec.rs index d42c63a6f1..51a3d49e3c 100644 --- a/crates/bevy_ecs/src/storage/blob_vec.rs +++ b/crates/bevy_ecs/src/storage/blob_vec.rs @@ -497,11 +497,13 @@ const fn padding_needed_for(layout: &Layout, align: usize) -> usize { #[cfg(test)] mod tests { + use super::BlobVec; use crate as bevy_ecs; // required for derive macros use crate::{component::Component, ptr::OwningPtr, world::World}; - - use super::BlobVec; - use alloc::rc::Rc; + use alloc::{ + rc::Rc, + string::{String, ToString}, + }; use core::{alloc::Layout, cell::RefCell}; /// # Safety diff --git a/crates/bevy_ecs/src/storage/sparse_set.rs b/crates/bevy_ecs/src/storage/sparse_set.rs index 55034ab98a..518333fa27 100644 --- a/crates/bevy_ecs/src/storage/sparse_set.rs +++ b/crates/bevy_ecs/src/storage/sparse_set.rs @@ -666,6 +666,7 @@ mod tests { entity::Entity, storage::SparseSet, }; + use alloc::{vec, vec::Vec}; #[derive(Debug, Eq, PartialEq)] struct Foo(usize); diff --git a/crates/bevy_ecs/src/storage/table/mod.rs b/crates/bevy_ecs/src/storage/table/mod.rs index 65e6eff552..ce33890751 100644 --- a/crates/bevy_ecs/src/storage/table/mod.rs +++ b/crates/bevy_ecs/src/storage/table/mod.rs @@ -822,6 +822,8 @@ mod tests { ptr::OwningPtr, storage::{Storages, TableBuilder, TableId, TableRow, Tables}, }; + use alloc::vec::Vec; + #[cfg(feature = "track_location")] use core::panic::Location; diff --git a/crates/bevy_ecs/src/storage/thin_array_ptr.rs b/crates/bevy_ecs/src/storage/thin_array_ptr.rs index 9c07332455..5654b6da67 100644 --- a/crates/bevy_ecs/src/storage/thin_array_ptr.rs +++ b/crates/bevy_ecs/src/storage/thin_array_ptr.rs @@ -14,6 +14,8 @@ use core::{ /// /// This type can be treated as a `ManuallyDrop>` without a built in length. To avoid /// memory leaks, [`drop`](Self::drop) must be called when no longer in use. +/// +/// [`Vec`]: alloc::vec::Vec pub struct ThinArrayPtr { data: NonNull, #[cfg(debug_assertions)] diff --git a/crates/bevy_ecs/src/system/builder.rs b/crates/bevy_ecs/src/system/builder.rs index fe68ea6bfa..9e7a015006 100644 --- a/crates/bevy_ecs/src/system/builder.rs +++ b/crates/bevy_ecs/src/system/builder.rs @@ -684,6 +684,7 @@ mod tests { prelude::{Component, Query}, system::{Local, RunSystemOnce}, }; + use alloc::vec; use super::*; diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index aebe1d8bd7..a9302615e0 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -2284,7 +2284,7 @@ mod tests { system::{Commands, Resource}, world::{CommandQueue, FromWorld, World}, }; - use alloc::sync::Arc; + use alloc::{string::String, sync::Arc, vec, vec::Vec}; use core::{ any::TypeId, sync::atomic::{AtomicUsize, Ordering}, diff --git a/crates/bevy_ecs/src/system/exclusive_system_param.rs b/crates/bevy_ecs/src/system/exclusive_system_param.rs index cc24cb7904..678d445233 100644 --- a/crates/bevy_ecs/src/system/exclusive_system_param.rs +++ b/crates/bevy_ecs/src/system/exclusive_system_param.rs @@ -126,6 +126,7 @@ all_tuples!( mod tests { use crate as bevy_ecs; use crate::{schedule::Schedule, system::Local, world::World}; + use alloc::vec::Vec; use bevy_ecs_macros::Resource; use core::marker::PhantomData; diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index b5020313c6..03b3d53238 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -116,6 +116,8 @@ //! - [`DynSystemParam`] //! - [`Vec

`] where `P: SystemParam` //! - [`ParamSet>`] where `P: SystemParam` +//! +//! [`Vec

`]: alloc::vec::Vec mod adapter_system; mod builder; @@ -317,8 +319,10 @@ pub fn assert_system_does_not_conflict); impl DropCheck { diff --git a/crates/bevy_ecs/src/world/deferred_world.rs b/crates/bevy_ecs/src/world/deferred_world.rs index ba1aa3bfff..446045d65b 100644 --- a/crates/bevy_ecs/src/world/deferred_world.rs +++ b/crates/bevy_ecs/src/world/deferred_world.rs @@ -192,6 +192,7 @@ impl<'w> DeferredWorld<'w> { /// [`EntityMut`]: crate::world::EntityMut /// [`&EntityHashSet`]: crate::entity::EntityHashSet /// [`EntityHashMap`]: crate::entity::EntityHashMap + /// [`Vec`]: alloc::vec::Vec #[inline] pub fn get_entity_mut( &mut self, @@ -323,6 +324,7 @@ impl<'w> DeferredWorld<'w> { /// [`EntityMut`]: crate::world::EntityMut /// [`&EntityHashSet`]: crate::entity::EntityHashSet /// [`EntityHashMap`]: crate::entity::EntityHashMap + /// [`Vec`]: alloc::vec::Vec #[inline] pub fn entity_mut(&mut self, entities: F) -> F::DeferredMut<'_> { self.get_entity_mut(entities).unwrap() diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index a011763687..9080be1b9b 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -4115,8 +4115,10 @@ unsafe impl DynamicComponentFetch for &'_ HashSet { #[cfg(test)] mod tests { + use alloc::{vec, vec::Vec}; use bevy_ptr::{OwningPtr, Ptr}; use core::panic::AssertUnwindSafe; + #[cfg(feature = "track_location")] use core::panic::Location; #[cfg(feature = "track_location")] diff --git a/crates/bevy_ecs/src/world/identifier.rs b/crates/bevy_ecs/src/world/identifier.rs index b1342e04dc..4ab38a2cdb 100644 --- a/crates/bevy_ecs/src/world/identifier.rs +++ b/crates/bevy_ecs/src/world/identifier.rs @@ -99,6 +99,7 @@ impl SparseSetIndex for WorldId { #[cfg(test)] mod tests { use super::*; + use alloc::vec::Vec; #[test] fn world_ids_unique() { diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 1a7f87cd91..8e8afdb34e 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -3766,7 +3766,13 @@ mod tests { system::Resource, world::error::EntityFetchError, }; - use alloc::sync::Arc; + use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + sync::Arc, + vec, + vec::Vec, + }; use bevy_ecs_macros::Component; use bevy_utils::{HashMap, HashSet}; use core::{ @@ -3774,7 +3780,7 @@ mod tests { panic, sync::atomic::{AtomicBool, AtomicU32, Ordering}, }; - use std::sync::Mutex; + use std::{println, sync::Mutex}; // For bevy_ecs_macros use crate as bevy_ecs; diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index 0da5c1c68a..8dd9cd9e5d 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -597,6 +597,7 @@ mod tests { components::{Children, Parent}, HierarchyEvent::{self, ChildAdded, ChildMoved, ChildRemoved}, }; + use alloc::{vec, vec::Vec}; use smallvec::{smallvec, SmallVec}; use bevy_ecs::{ diff --git a/crates/bevy_hierarchy/src/hierarchy.rs b/crates/bevy_hierarchy/src/hierarchy.rs index 43d6cdd1fb..7ab31a5885 100644 --- a/crates/bevy_hierarchy/src/hierarchy.rs +++ b/crates/bevy_hierarchy/src/hierarchy.rs @@ -247,6 +247,7 @@ fn component_clone_parent(world: &mut DeferredWorld, ctx: &mut ComponentCloneCtx #[cfg(test)] mod tests { + use alloc::{borrow::ToOwned, string::String, vec, vec::Vec}; use bevy_ecs::{ component::Component, system::Commands, diff --git a/crates/bevy_hierarchy/src/lib.rs b/crates/bevy_hierarchy/src/lib.rs index ec42846b14..2e8beea501 100644 --- a/crates/bevy_hierarchy/src/lib.rs +++ b/crates/bevy_hierarchy/src/lib.rs @@ -4,7 +4,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! Parent-child relationships for Bevy entities. //! @@ -52,6 +52,9 @@ //! [plugin]: HierarchyPlugin //! [query extension methods]: HierarchyQueryExt +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; mod components; diff --git a/crates/bevy_hierarchy/src/query_extension.rs b/crates/bevy_hierarchy/src/query_extension.rs index 35ebaf8025..1ab3ec9385 100644 --- a/crates/bevy_hierarchy/src/query_extension.rs +++ b/crates/bevy_hierarchy/src/query_extension.rs @@ -312,6 +312,7 @@ where #[cfg(test)] mod tests { + use alloc::vec::Vec; use bevy_ecs::{ prelude::Component, system::{Query, SystemState}, diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index 6762627e14..cf4ad9e315 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -1641,6 +1641,7 @@ mod tests { RawGamepadButtonChangedEvent, RawGamepadEvent, }; use crate::ButtonState; + use alloc::string::ToString; use bevy_app::{App, PreUpdate}; use bevy_ecs::entity::Entity; use bevy_ecs::event::Events; diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index 5826d174f4..2da2c89cce 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -4,7 +4,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! Input functionality for the [Bevy game engine](https://bevyengine.org/). //! @@ -12,6 +12,9 @@ //! //! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs. +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; mod axis; diff --git a/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs b/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs index e524d973a6..fa0292572f 100644 --- a/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs +++ b/crates/bevy_math/src/bounding/bounded2d/primitive_impls.rs @@ -443,6 +443,7 @@ impl Bounded2d for Capsule2d { #[cfg(test)] mod tests { use core::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_4, FRAC_PI_6, TAU}; + use std::println; use approx::assert_abs_diff_eq; use glam::Vec2; diff --git a/crates/bevy_math/src/cubic_splines/mod.rs b/crates/bevy_math/src/cubic_splines/mod.rs index e179c89210..32e13f6720 100644 --- a/crates/bevy_math/src/cubic_splines/mod.rs +++ b/crates/bevy_math/src/cubic_splines/mod.rs @@ -995,6 +995,13 @@ impl CubicSegment

{ } /// Calculate polynomial coefficients for the cubic curve using a characteristic matrix. + #[cfg_attr( + not(feature = "alloc"), + expect( + dead_code, + reason = "Method only used when `alloc` feature is enabled." + ) + )] #[inline] fn coefficients(p: [P; 4], char_matrix: [[f32; 4]; 4]) -> Self { let [c0, c1, c2, c3] = char_matrix; @@ -1375,6 +1382,13 @@ impl RationalSegment

{ } /// Calculate polynomial coefficients for the cubic polynomials using a characteristic matrix. + #[cfg_attr( + not(feature = "alloc"), + expect( + dead_code, + reason = "Method only used when `alloc` feature is enabled." + ) + )] #[inline] fn coefficients( control_points: [P; 4], diff --git a/crates/bevy_math/src/curve/adaptors.rs b/crates/bevy_math/src/curve/adaptors.rs index 8b27dc5387..afc34837d3 100644 --- a/crates/bevy_math/src/curve/adaptors.rs +++ b/crates/bevy_math/src/curve/adaptors.rs @@ -10,7 +10,10 @@ use core::fmt::{self, Debug}; use core::marker::PhantomData; #[cfg(feature = "bevy_reflect")] -use bevy_reflect::{utility::GenericTypePathCell, FromReflect, Reflect, TypePath}; +use { + alloc::format, + bevy_reflect::{utility::GenericTypePathCell, FromReflect, Reflect, TypePath}, +}; #[cfg(feature = "bevy_reflect")] mod paths { diff --git a/crates/bevy_math/src/curve/cores.rs b/crates/bevy_math/src/curve/cores.rs index a88aecfb67..35bffe9018 100644 --- a/crates/bevy_math/src/curve/cores.rs +++ b/crates/bevy_math/src/curve/cores.rs @@ -697,6 +697,7 @@ pub fn uneven_interp(times: &[f32], t: f32) -> InterpolationDatum { mod tests { use super::{ChunkedUnevenCore, EvenCore, UnevenCore}; use crate::curve::{cores::InterpolationDatum, interval}; + use alloc::vec; use approx::{assert_abs_diff_eq, AbsDiffEq}; fn approx_between(datum: InterpolationDatum, start: T, end: T, p: f32) -> bool diff --git a/crates/bevy_math/src/curve/interval.rs b/crates/bevy_math/src/curve/interval.rs index 6e5f4465ae..007e523c95 100644 --- a/crates/bevy_math/src/curve/interval.rs +++ b/crates/bevy_math/src/curve/interval.rs @@ -201,6 +201,7 @@ mod tests { use crate::ops; use super::*; + use alloc::vec::Vec; use approx::{assert_abs_diff_eq, AbsDiffEq}; #[test] diff --git a/crates/bevy_math/src/curve/mod.rs b/crates/bevy_math/src/curve/mod.rs index 43548f0893..659f4fee68 100644 --- a/crates/bevy_math/src/curve/mod.rs +++ b/crates/bevy_math/src/curve/mod.rs @@ -1005,6 +1005,7 @@ pub enum ResamplingError { mod tests { use super::*; use crate::{ops, Quat}; + use alloc::vec::Vec; use approx::{assert_abs_diff_eq, AbsDiffEq}; use core::f32::consts::TAU; use glam::*; diff --git a/crates/bevy_math/src/curve/sample_curves.rs b/crates/bevy_math/src/curve/sample_curves.rs index 15ca51c2a3..681500328b 100644 --- a/crates/bevy_math/src/curve/sample_curves.rs +++ b/crates/bevy_math/src/curve/sample_curves.rs @@ -4,6 +4,7 @@ use super::cores::{EvenCore, EvenCoreError, UnevenCore, UnevenCoreError}; use super::{Curve, Interval}; use crate::StableInterpolate; +use alloc::format; use core::any::type_name; use core::fmt::{self, Debug}; @@ -369,6 +370,7 @@ mod tests { //! - function pointers use super::{SampleCurve, UnevenSampleCurve}; use crate::{curve::Interval, VectorSpace}; + use alloc::boxed::Box; use bevy_reflect::Reflect; #[test] diff --git a/crates/bevy_math/src/direction.rs b/crates/bevy_math/src/direction.rs index 5e11d1434b..2da99c687b 100644 --- a/crates/bevy_math/src/direction.rs +++ b/crates/bevy_math/src/direction.rs @@ -8,9 +8,13 @@ use derive_more::derive::Into; #[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; + #[cfg(all(feature = "serialize", feature = "bevy_reflect"))] use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; +#[cfg(all(debug_assertions, feature = "std"))] +use std::eprintln; + /// An error indicating that a direction is invalid. #[derive(Debug, PartialEq)] pub enum InvalidDirectionError { diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index b589d66182..b66dffcf56 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -13,7 +13,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! Provides math types and functionality for the Bevy game engine. //! @@ -21,6 +21,9 @@ //! matrices like [`Mat2`], [`Mat3`] and [`Mat4`] and orientation representations //! like [`Quat`]. +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "alloc")] extern crate alloc; diff --git a/crates/bevy_mikktspace/src/lib.rs b/crates/bevy_mikktspace/src/lib.rs index fe514e208e..519e5894f0 100644 --- a/crates/bevy_mikktspace/src/lib.rs +++ b/crates/bevy_mikktspace/src/lib.rs @@ -11,7 +11,10 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; extern crate alloc; diff --git a/crates/bevy_reflect/derive/src/impls/func/into_return.rs b/crates/bevy_reflect/derive/src/impls/func/into_return.rs index c47c328f9a..f7d1e0b889 100644 --- a/crates/bevy_reflect/derive/src/impls/func/into_return.rs +++ b/crates/bevy_reflect/derive/src/impls/func/into_return.rs @@ -14,7 +14,7 @@ pub(crate) fn impl_into_return( quote! { impl #impl_generics #bevy_reflect::func::IntoReturn for #type_path #ty_generics #where_reflect_clause { fn into_return<'into_return>(self) -> #bevy_reflect::func::Return<'into_return> where Self: 'into_return { - #bevy_reflect::func::Return::Owned(Box::new(self)) + #bevy_reflect::func::Return::Owned(#bevy_reflect::__macro_exports::alloc_utils::Box::new(self)) } } diff --git a/crates/bevy_reflect/src/array.rs b/crates/bevy_reflect/src/array.rs index 0753c0e345..0fee779b05 100644 --- a/crates/bevy_reflect/src/array.rs +++ b/crates/bevy_reflect/src/array.rs @@ -513,6 +513,8 @@ pub fn array_debug(dyn_array: &dyn Array, f: &mut Formatter<'_>) -> core::fmt::R #[cfg(test)] mod tests { use crate::Reflect; + use alloc::boxed::Box; + #[test] fn next_index_increment() { const SIZE: usize = if cfg!(debug_assertions) { diff --git a/crates/bevy_reflect/src/attributes.rs b/crates/bevy_reflect/src/attributes.rs index 0e751fa57a..0e31b60398 100644 --- a/crates/bevy_reflect/src/attributes.rs +++ b/crates/bevy_reflect/src/attributes.rs @@ -181,6 +181,7 @@ mod tests { use super::*; use crate as bevy_reflect; use crate::{type_info::Typed, TypeInfo, VariantInfo}; + use alloc::{format, string::String}; use core::ops::RangeInclusive; #[derive(Reflect, PartialEq, Debug)] diff --git a/crates/bevy_reflect/src/enums/mod.rs b/crates/bevy_reflect/src/enums/mod.rs index 95a94e68e9..89b5f17b1c 100644 --- a/crates/bevy_reflect/src/enums/mod.rs +++ b/crates/bevy_reflect/src/enums/mod.rs @@ -12,6 +12,7 @@ pub use variants::*; mod tests { use crate as bevy_reflect; use crate::*; + use alloc::boxed::Box; #[derive(Reflect, Debug, PartialEq)] enum MyEnum { diff --git a/crates/bevy_reflect/src/func/args/arg.rs b/crates/bevy_reflect/src/func/args/arg.rs index 60698a3d7e..35e32c6067 100644 --- a/crates/bevy_reflect/src/func/args/arg.rs +++ b/crates/bevy_reflect/src/func/args/arg.rs @@ -2,12 +2,9 @@ use crate::{ func::args::{ArgError, FromArg, Ownership}, PartialReflect, Reflect, TypePath, }; -use alloc::boxed::Box; +use alloc::{boxed::Box, string::ToString}; use core::ops::Deref; -#[cfg(not(feature = "std"))] -use alloc::{format, vec}; - /// Represents an argument that can be passed to a [`DynamicFunction`] or [`DynamicFunctionMut`]. /// /// [`DynamicFunction`]: crate::func::DynamicFunction diff --git a/crates/bevy_reflect/src/func/args/error.rs b/crates/bevy_reflect/src/func/args/error.rs index 65c4caa6e8..bd32bd5e5a 100644 --- a/crates/bevy_reflect/src/func/args/error.rs +++ b/crates/bevy_reflect/src/func/args/error.rs @@ -4,9 +4,6 @@ use thiserror::Error; use crate::func::args::Ownership; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// An error that occurs when converting an [argument]. /// /// [argument]: crate::func::args::Arg diff --git a/crates/bevy_reflect/src/func/args/from_arg.rs b/crates/bevy_reflect/src/func/args/from_arg.rs index ddb1e014eb..88d04aefe7 100644 --- a/crates/bevy_reflect/src/func/args/from_arg.rs +++ b/crates/bevy_reflect/src/func/args/from_arg.rs @@ -1,8 +1,5 @@ use crate::func::args::{Arg, ArgError}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A trait for types that can be created from an [`Arg`]. /// /// This trait exists so that types can be automatically converted into an [`Arg`] diff --git a/crates/bevy_reflect/src/func/args/info.rs b/crates/bevy_reflect/src/func/args/info.rs index 3919771f34..b1a81f3059 100644 --- a/crates/bevy_reflect/src/func/args/info.rs +++ b/crates/bevy_reflect/src/func/args/info.rs @@ -6,9 +6,6 @@ use crate::{ Type, TypePath, }; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// Type information for an [`Arg`] used in a [`DynamicFunction`] or [`DynamicFunctionMut`]. /// /// [`Arg`]: crate::func::args::Arg diff --git a/crates/bevy_reflect/src/func/args/list.rs b/crates/bevy_reflect/src/func/args/list.rs index 145414424f..de8bcdcb92 100644 --- a/crates/bevy_reflect/src/func/args/list.rs +++ b/crates/bevy_reflect/src/func/args/list.rs @@ -10,9 +10,6 @@ use alloc::{ collections::vec_deque::{Iter, VecDeque}, }; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A list of arguments that can be passed to a [`DynamicFunction`] or [`DynamicFunctionMut`]. /// /// # Example @@ -308,6 +305,7 @@ impl<'a> ArgList<'a> { #[cfg(test)] mod tests { use super::*; + use alloc::string::String; #[test] fn should_push_arguments_in_order() { diff --git a/crates/bevy_reflect/src/func/args/ownership.rs b/crates/bevy_reflect/src/func/args/ownership.rs index 448efed9f6..b9395c742f 100644 --- a/crates/bevy_reflect/src/func/args/ownership.rs +++ b/crates/bevy_reflect/src/func/args/ownership.rs @@ -1,8 +1,5 @@ use core::fmt::{Display, Formatter}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A trait for getting the ownership of a type. /// /// This trait exists so that [`TypedFunction`] can automatically generate diff --git a/crates/bevy_reflect/src/func/dynamic_function.rs b/crates/bevy_reflect/src/func/dynamic_function.rs index d513cb6808..408cdda640 100644 --- a/crates/bevy_reflect/src/func/dynamic_function.rs +++ b/crates/bevy_reflect/src/func/dynamic_function.rs @@ -15,9 +15,6 @@ use alloc::{borrow::Cow, boxed::Box, sync::Arc}; use bevy_reflect_derive::impl_type_path; use core::fmt::{Debug, Formatter}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// An [`Arc`] containing a callback to a reflected function. /// /// The `Arc` is used to both ensure that it is `Send + Sync` @@ -473,6 +470,7 @@ mod tests { use crate::func::signature::ArgumentSignature; use crate::func::{FunctionError, IntoReturn, SignatureInfo}; use crate::Type; + use alloc::{format, string::String, vec, vec::Vec}; use bevy_utils::HashSet; use core::ops::Add; diff --git a/crates/bevy_reflect/src/func/dynamic_function_internal.rs b/crates/bevy_reflect/src/func/dynamic_function_internal.rs index 427de1263d..4f06c5c2d7 100644 --- a/crates/bevy_reflect/src/func/dynamic_function_internal.rs +++ b/crates/bevy_reflect/src/func/dynamic_function_internal.rs @@ -1,7 +1,7 @@ use crate::func::args::ArgCount; use crate::func::signature::{ArgListSignature, ArgumentSignature}; use crate::func::{ArgList, FunctionError, FunctionInfo, FunctionOverloadError}; -use alloc::borrow::Cow; +use alloc::{borrow::Cow, vec, vec::Vec}; use bevy_utils::HashMap; use core::fmt::{Debug, Formatter}; diff --git a/crates/bevy_reflect/src/func/dynamic_function_mut.rs b/crates/bevy_reflect/src/func/dynamic_function_mut.rs index bcbf6a9633..c9615f2d91 100644 --- a/crates/bevy_reflect/src/func/dynamic_function_mut.rs +++ b/crates/bevy_reflect/src/func/dynamic_function_mut.rs @@ -1,9 +1,6 @@ use alloc::{borrow::Cow, boxed::Box, sync::Arc}; use core::fmt::{Debug, Formatter}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - use crate::func::{ args::{ArgCount, ArgList}, dynamic_function_internal::DynamicFunctionInternal, @@ -381,6 +378,7 @@ impl<'env> IntoFunctionMut<'env, ()> for DynamicFunctionMut<'env> { mod tests { use super::*; use crate::func::{FunctionError, IntoReturn, SignatureInfo}; + use alloc::vec; use core::ops::Add; #[test] diff --git a/crates/bevy_reflect/src/func/error.rs b/crates/bevy_reflect/src/func/error.rs index ad6796be19..7f0fae4662 100644 --- a/crates/bevy_reflect/src/func/error.rs +++ b/crates/bevy_reflect/src/func/error.rs @@ -7,9 +7,6 @@ use alloc::borrow::Cow; use bevy_utils::HashSet; use thiserror::Error; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// An error that occurs when calling a [`DynamicFunction`] or [`DynamicFunctionMut`]. /// /// [`DynamicFunction`]: crate::func::DynamicFunction diff --git a/crates/bevy_reflect/src/func/function.rs b/crates/bevy_reflect/src/func/function.rs index 0d8e94ca95..2c4c8f7527 100644 --- a/crates/bevy_reflect/src/func/function.rs +++ b/crates/bevy_reflect/src/func/function.rs @@ -8,9 +8,6 @@ use crate::{ use alloc::borrow::Cow; use core::fmt::Debug; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A trait used to power [function-like] operations via [reflection]. /// /// This trait allows types to be called like regular functions @@ -74,6 +71,7 @@ pub trait Function: PartialReflect + Debug { mod tests { use super::*; use crate::func::IntoFunction; + use alloc::boxed::Box; #[test] fn should_call_dyn_function() { diff --git a/crates/bevy_reflect/src/func/info.rs b/crates/bevy_reflect/src/func/info.rs index 797b97e7e1..40f90aa505 100644 --- a/crates/bevy_reflect/src/func/info.rs +++ b/crates/bevy_reflect/src/func/info.rs @@ -1,9 +1,6 @@ -use alloc::{borrow::Cow, vec}; +use alloc::{borrow::Cow, boxed::Box, vec, vec::Vec}; use core::fmt::{Debug, Formatter}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - use crate::{ func::args::{ArgCount, ArgCountOutOfBoundsError, ArgInfo, GetOwnership, Ownership}, func::signature::ArgumentSignature, diff --git a/crates/bevy_reflect/src/func/into_function.rs b/crates/bevy_reflect/src/func/into_function.rs index e913045f8c..d3276a6bd7 100644 --- a/crates/bevy_reflect/src/func/into_function.rs +++ b/crates/bevy_reflect/src/func/into_function.rs @@ -1,8 +1,5 @@ use crate::func::{DynamicFunction, ReflectFn, TypedFunction}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A trait for types that can be converted into a [`DynamicFunction`]. /// /// This trait is automatically implemented for any type that implements diff --git a/crates/bevy_reflect/src/func/into_function_mut.rs b/crates/bevy_reflect/src/func/into_function_mut.rs index 8f7f1b0a6d..38eae0aee4 100644 --- a/crates/bevy_reflect/src/func/into_function_mut.rs +++ b/crates/bevy_reflect/src/func/into_function_mut.rs @@ -1,8 +1,5 @@ use crate::func::{DynamicFunctionMut, ReflectFnMut, TypedFunction}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// A trait for types that can be converted into a [`DynamicFunctionMut`]. /// /// This trait is automatically implemented for any type that implements diff --git a/crates/bevy_reflect/src/func/macros.rs b/crates/bevy_reflect/src/func/macros.rs index 410aaba456..3fb93a2230 100644 --- a/crates/bevy_reflect/src/func/macros.rs +++ b/crates/bevy_reflect/src/func/macros.rs @@ -1,6 +1,3 @@ -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// Helper macro to implement the necessary traits for function reflection. /// /// This macro calls the following macros: diff --git a/crates/bevy_reflect/src/func/reflect_fn.rs b/crates/bevy_reflect/src/func/reflect_fn.rs index 38a18141fc..5d6f61db70 100644 --- a/crates/bevy_reflect/src/func/reflect_fn.rs +++ b/crates/bevy_reflect/src/func/reflect_fn.rs @@ -1,8 +1,5 @@ use variadics_please::all_tuples; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - use crate::{ func::{ args::{ArgCount, FromArg}, diff --git a/crates/bevy_reflect/src/func/reflect_fn_mut.rs b/crates/bevy_reflect/src/func/reflect_fn_mut.rs index 760e657037..e77adc82cc 100644 --- a/crates/bevy_reflect/src/func/reflect_fn_mut.rs +++ b/crates/bevy_reflect/src/func/reflect_fn_mut.rs @@ -1,8 +1,5 @@ use variadics_please::all_tuples; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - use crate::{ func::{ args::{ArgCount, FromArg}, diff --git a/crates/bevy_reflect/src/func/registry.rs b/crates/bevy_reflect/src/func/registry.rs index cd9a0d270d..4bb38603fb 100644 --- a/crates/bevy_reflect/src/func/registry.rs +++ b/crates/bevy_reflect/src/func/registry.rs @@ -2,9 +2,6 @@ use alloc::{borrow::Cow, sync::Arc}; use core::fmt::Debug; use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - use bevy_utils::HashMap; use crate::func::{ @@ -359,6 +356,7 @@ impl FunctionRegistryArc { mod tests { use super::*; use crate::func::{ArgList, IntoFunction}; + use alloc::format; #[test] fn should_register_function() { diff --git a/crates/bevy_reflect/src/func/return_type.rs b/crates/bevy_reflect/src/func/return_type.rs index 3d1153912c..bab3c04b25 100644 --- a/crates/bevy_reflect/src/func/return_type.rs +++ b/crates/bevy_reflect/src/func/return_type.rs @@ -1,9 +1,6 @@ use crate::PartialReflect; use alloc::boxed::Box; -#[cfg(not(feature = "std"))] -use alloc::{format, vec}; - /// The return type of a [`DynamicFunction`] or [`DynamicFunctionMut`]. /// /// [`DynamicFunction`]: crate::func::DynamicFunction diff --git a/crates/bevy_reflect/src/func/signature.rs b/crates/bevy_reflect/src/func/signature.rs index 965ff401e0..278f18f1f5 100644 --- a/crates/bevy_reflect/src/func/signature.rs +++ b/crates/bevy_reflect/src/func/signature.rs @@ -14,6 +14,7 @@ use crate::func::args::ArgInfo; use crate::func::{ArgList, SignatureInfo}; use crate::Type; +use alloc::boxed::Box; use bevy_utils::hashbrown::Equivalent; use core::borrow::Borrow; use core::fmt::{Debug, Formatter}; @@ -203,6 +204,7 @@ impl From<&ArgList<'_>> for ArgumentSignature { mod tests { use super::*; use crate::func::TypedFunction; + use alloc::{format, string::String, vec}; #[test] fn should_generate_signature_from_function_info() { diff --git a/crates/bevy_reflect/src/generics.rs b/crates/bevy_reflect/src/generics.rs index fa91fc35c5..f64cefe2d9 100644 --- a/crates/bevy_reflect/src/generics.rs +++ b/crates/bevy_reflect/src/generics.rs @@ -241,6 +241,7 @@ mod tests { use super::*; use crate as bevy_reflect; use crate::{Reflect, Typed}; + use alloc::string::String; use core::fmt::Debug; #[test] diff --git a/crates/bevy_reflect/src/impls/glam.rs b/crates/bevy_reflect/src/impls/glam.rs index cd7551cf74..d8d70d10dd 100644 --- a/crates/bevy_reflect/src/impls/glam.rs +++ b/crates/bevy_reflect/src/impls/glam.rs @@ -378,7 +378,7 @@ impl_reflect_opaque!(::glam::BVec4A(Debug, Default, Deserialize, Serialize)); #[cfg(test)] mod tests { - use alloc::format; + use alloc::{format, string::String}; use ron::{ ser::{to_string_pretty, PrettyConfig}, Deserializer, diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index c5e8cc3a25..2e79883c33 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -2428,7 +2428,7 @@ mod tests { self as bevy_reflect, Enum, FromReflect, PartialReflect, Reflect, ReflectSerialize, TypeInfo, TypeRegistry, Typed, VariantInfo, VariantType, }; - use alloc::collections::BTreeMap; + use alloc::{collections::BTreeMap, string::String, vec}; use bevy_utils::{Duration, HashMap, Instant}; use core::f32::consts::{PI, TAU}; use static_assertions::assert_impl_all; diff --git a/crates/bevy_reflect/src/kind.rs b/crates/bevy_reflect/src/kind.rs index d5d16715c0..3eef10d0e5 100644 --- a/crates/bevy_reflect/src/kind.rs +++ b/crates/bevy_reflect/src/kind.rs @@ -274,6 +274,7 @@ impl ReflectOwned { #[cfg(test)] mod tests { + use alloc::vec; use std::collections::HashSet; use super::*; diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index c6e5ba0b45..e84bee274b 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -557,7 +557,10 @@ //! [`ArgList`]: crate::func::ArgList //! [derive `Reflect`]: derive@crate::Reflect -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; extern crate alloc; @@ -712,7 +715,14 @@ pub mod __macro_exports { #[allow(clippy::disallowed_types, clippy::approx_constant)] mod tests { use ::serde::{de::DeserializeSeed, Deserialize, Serialize}; - use alloc::borrow::Cow; + use alloc::{ + borrow::Cow, + boxed::Box, + format, + string::{String, ToString}, + vec, + vec::Vec, + }; use bevy_utils::HashMap; use core::{ any::TypeId, @@ -2556,6 +2566,8 @@ bevy_reflect::tests::Test { #[test] fn should_reflect_remote_type() { mod external_crate { + use alloc::string::String; + #[derive(Debug, Default)] pub struct TheirType { pub value: String, @@ -2631,6 +2643,8 @@ bevy_reflect::tests::Test { #[test] fn should_reflect_remote_value_type() { mod external_crate { + use alloc::string::String; + #[derive(Clone, Debug, Default)] pub struct TheirType { pub value: String, @@ -2714,6 +2728,8 @@ bevy_reflect::tests::Test { // error[E0433]: failed to resolve: use of undeclared crate or module `external_crate` // ``` pub mod external_crate { + use alloc::string::String; + pub struct TheirType { pub value: String, } @@ -2735,6 +2751,8 @@ bevy_reflect::tests::Test { #[test] fn should_reflect_remote_enum() { mod external_crate { + use alloc::string::String; + #[derive(Debug, PartialEq, Eq)] pub enum TheirType { Unit, @@ -2899,6 +2917,8 @@ bevy_reflect::tests::Test { #[test] fn should_take_remote_type() { mod external_crate { + use alloc::string::String; + #[derive(Debug, Default, PartialEq, Eq)] pub struct TheirType { pub value: String, @@ -2931,6 +2951,8 @@ bevy_reflect::tests::Test { #[test] fn should_try_take_remote_type() { mod external_crate { + use alloc::string::String; + #[derive(Debug, Default, PartialEq, Eq)] pub struct TheirType { pub value: String, diff --git a/crates/bevy_reflect/src/list.rs b/crates/bevy_reflect/src/list.rs index 58fca368b8..2aff62241f 100644 --- a/crates/bevy_reflect/src/list.rs +++ b/crates/bevy_reflect/src/list.rs @@ -535,6 +535,7 @@ pub fn list_debug(dyn_list: &dyn List, f: &mut Formatter<'_>) -> core::fmt::Resu mod tests { use super::DynamicList; use crate::Reflect; + use alloc::{boxed::Box, vec}; use core::assert_eq; #[test] diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index e5205e90af..74743a0df1 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -631,6 +631,10 @@ pub fn map_try_apply(a: &mut M, b: &dyn PartialReflect) -> Result<(), Ap #[cfg(test)] mod tests { use super::{DynamicMap, Map}; + use alloc::{ + borrow::ToOwned, + string::{String, ToString}, + }; #[test] fn test_into_iter() { diff --git a/crates/bevy_reflect/src/path/mod.rs b/crates/bevy_reflect/src/path/mod.rs index 3fe0504cf7..f25870d31d 100644 --- a/crates/bevy_reflect/src/path/mod.rs +++ b/crates/bevy_reflect/src/path/mod.rs @@ -507,6 +507,7 @@ mod tests { use super::*; use crate as bevy_reflect; use crate::*; + use alloc::vec; #[derive(Reflect)] struct A { diff --git a/crates/bevy_reflect/src/serde/de/error_utils.rs b/crates/bevy_reflect/src/serde/de/error_utils.rs index f028976805..d570c47f0c 100644 --- a/crates/bevy_reflect/src/serde/de/error_utils.rs +++ b/crates/bevy_reflect/src/serde/de/error_utils.rs @@ -1,6 +1,9 @@ use core::fmt::Display; use serde::de::Error; +#[cfg(feature = "debug_stack")] +use std::thread_local; + #[cfg(feature = "debug_stack")] thread_local! { /// The thread-local [`TypeInfoStack`] used for debugging. diff --git a/crates/bevy_reflect/src/serde/de/mod.rs b/crates/bevy_reflect/src/serde/de/mod.rs index e55897166e..e8b2df862d 100644 --- a/crates/bevy_reflect/src/serde/de/mod.rs +++ b/crates/bevy_reflect/src/serde/de/mod.rs @@ -24,11 +24,16 @@ mod tuples; #[cfg(test)] mod tests { + use alloc::{ + boxed::Box, + string::{String, ToString}, + vec, + vec::Vec, + }; use bincode::Options; use core::{any::TypeId, f32::consts::PI, ops::RangeInclusive}; - use serde::{de::IgnoredAny, Deserializer}; - use serde::{de::DeserializeSeed, Deserialize}; + use serde::{de::IgnoredAny, Deserializer}; use bevy_utils::{HashMap, HashSet}; diff --git a/crates/bevy_reflect/src/serde/mod.rs b/crates/bevy_reflect/src/serde/mod.rs index 3fcaa6aafc..d35af8922e 100644 --- a/crates/bevy_reflect/src/serde/mod.rs +++ b/crates/bevy_reflect/src/serde/mod.rs @@ -189,7 +189,7 @@ mod tests { use crate::serde::{DeserializeWithRegistry, ReflectDeserializeWithRegistry}; use crate::serde::{ReflectSerializeWithRegistry, SerializeWithRegistry}; use crate::{ReflectFromReflect, TypePath}; - use alloc::sync::Arc; + use alloc::{format, string::String, sync::Arc, vec, vec::Vec}; use bevy_reflect_derive::reflect_trait; use core::any::TypeId; use core::fmt::{Debug, Formatter}; diff --git a/crates/bevy_reflect/src/serde/ser/error_utils.rs b/crates/bevy_reflect/src/serde/ser/error_utils.rs index 8e6570c669..d252e7f591 100644 --- a/crates/bevy_reflect/src/serde/ser/error_utils.rs +++ b/crates/bevy_reflect/src/serde/ser/error_utils.rs @@ -1,6 +1,9 @@ use core::fmt::Display; use serde::ser::Error; +#[cfg(feature = "debug_stack")] +use std::thread_local; + #[cfg(feature = "debug_stack")] thread_local! { /// The thread-local [`TypeInfoStack`] used for debugging. diff --git a/crates/bevy_reflect/src/serde/ser/mod.rs b/crates/bevy_reflect/src/serde/ser/mod.rs index 53afacde37..77f2b9d0fe 100644 --- a/crates/bevy_reflect/src/serde/ser/mod.rs +++ b/crates/bevy_reflect/src/serde/ser/mod.rs @@ -25,6 +25,12 @@ mod tests { serde::{ReflectSerializer, ReflectSerializerProcessor}, PartialReflect, Reflect, ReflectSerialize, Struct, TypeRegistry, }; + use alloc::{ + boxed::Box, + string::{String, ToString}, + vec, + vec::Vec, + }; use bevy_utils::{HashMap, HashSet}; use core::{any::TypeId, f32::consts::PI, ops::RangeInclusive}; use ron::{extensions::Extensions, ser::PrettyConfig}; @@ -647,6 +653,7 @@ mod tests { mod functions { use super::*; use crate::func::{DynamicFunction, IntoFunction}; + use alloc::string::ToString; #[test] fn should_not_serialize_function() { diff --git a/crates/bevy_reflect/src/set.rs b/crates/bevy_reflect/src/set.rs index 0d46d9f9df..663b99715c 100644 --- a/crates/bevy_reflect/src/set.rs +++ b/crates/bevy_reflect/src/set.rs @@ -498,6 +498,7 @@ pub fn set_try_apply(a: &mut S, b: &dyn PartialReflect) -> Result<(), Ap #[cfg(test)] mod tests { use super::DynamicSet; + use alloc::string::{String, ToString}; #[test] fn test_into_iter() { diff --git a/crates/bevy_reflect/src/type_info.rs b/crates/bevy_reflect/src/type_info.rs index 4ccac40508..2add261aa2 100644 --- a/crates/bevy_reflect/src/type_info.rs +++ b/crates/bevy_reflect/src/type_info.rs @@ -547,6 +547,8 @@ pub(crate) use impl_type_methods; /// For example, [`i32`] cannot be broken down any further, so it is represented by an [`OpaqueInfo`]. /// And while [`String`] itself is a struct, its fields are private, so we don't really treat /// it _as_ a struct. It therefore makes more sense to represent it as an [`OpaqueInfo`]. +/// +/// [`String`]: alloc::string::String #[derive(Debug, Clone)] pub struct OpaqueInfo { ty: Type, @@ -585,6 +587,7 @@ impl OpaqueInfo { #[cfg(test)] mod tests { use super::*; + use alloc::vec::Vec; #[test] fn should_return_error_on_invalid_cast() { diff --git a/crates/bevy_reflect/src/type_info_stack.rs b/crates/bevy_reflect/src/type_info_stack.rs index 8f1161485f..cdc19244de 100644 --- a/crates/bevy_reflect/src/type_info_stack.rs +++ b/crates/bevy_reflect/src/type_info_stack.rs @@ -1,12 +1,10 @@ use crate::TypeInfo; +use alloc::vec::Vec; use core::{ fmt::{Debug, Formatter}, slice::Iter, }; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, vec}; - /// Helper struct for managing a stack of [`TypeInfo`] instances. /// /// This is useful for tracking the type hierarchy when serializing and deserializing types. diff --git a/crates/bevy_reflect/src/utility.rs b/crates/bevy_reflect/src/utility.rs index f106baf622..996a661c70 100644 --- a/crates/bevy_reflect/src/utility.rs +++ b/crates/bevy_reflect/src/utility.rs @@ -24,6 +24,7 @@ pub trait TypedProperty: sealed::Sealed { /// Used to store a [`String`] in a [`GenericTypePathCell`] as part of a [`TypePath`] implementation. /// /// [`TypePath`]: crate::TypePath +/// [`String`]: alloc::string::String pub struct TypePathComponent; mod sealed { diff --git a/crates/bevy_state/src/lib.rs b/crates/bevy_state/src/lib.rs index 572330de4c..cdcb37f4ca 100644 --- a/crates/bevy_state/src/lib.rs +++ b/crates/bevy_state/src/lib.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! In Bevy, states are app-wide interdependent, finite state machines that are generally used to model the large scale structure of your program: whether a game is paused, if the player is in combat, if assets are loaded and so on. //! @@ -38,6 +38,9 @@ )] #![cfg_attr(any(docsrs, docsrs_dep), feature(rustdoc_internals))] +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; #[cfg(feature = "bevy_app")] diff --git a/crates/bevy_state/src/state/mod.rs b/crates/bevy_state/src/state/mod.rs index d02d3a32ed..c71827cc5f 100644 --- a/crates/bevy_state/src/state/mod.rs +++ b/crates/bevy_state/src/state/mod.rs @@ -17,6 +17,7 @@ pub use transitions::*; #[cfg(test)] mod tests { + use alloc::vec::Vec; use bevy_ecs::{event::EventRegistry, prelude::*}; use bevy_state_macros::{States, SubStates}; diff --git a/crates/bevy_tasks/src/lib.rs b/crates/bevy_tasks/src/lib.rs index 97b13b0052..1cd6d6786e 100644 --- a/crates/bevy_tasks/src/lib.rs +++ b/crates/bevy_tasks/src/lib.rs @@ -4,8 +4,11 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; extern crate alloc; diff --git a/crates/bevy_tasks/src/single_threaded_task_pool.rs b/crates/bevy_tasks/src/single_threaded_task_pool.rs index 0a5678b066..668408fefb 100644 --- a/crates/bevy_tasks/src/single_threaded_task_pool.rs +++ b/crates/bevy_tasks/src/single_threaded_task_pool.rs @@ -3,6 +3,9 @@ use core::{cell::RefCell, future::Future, marker::PhantomData, mem}; use crate::Task; +#[cfg(feature = "std")] +use std::thread_local; + #[cfg(feature = "portable-atomic")] use portable_atomic_util::Arc; diff --git a/crates/bevy_tasks/src/slice.rs b/crates/bevy_tasks/src/slice.rs index 5f964a4561..a705314a34 100644 --- a/crates/bevy_tasks/src/slice.rs +++ b/crates/bevy_tasks/src/slice.rs @@ -215,6 +215,7 @@ impl ParallelSliceMut for S where S: AsMut<[T]> {} #[cfg(test)] mod tests { use crate::*; + use alloc::vec; #[test] fn test_par_chunks_map() { diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 94f59bbce9..9e5509300f 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -1,12 +1,16 @@ +use alloc::{boxed::Box, format, string::String, vec::Vec}; use core::{future::Future, marker::PhantomData, mem, panic::AssertUnwindSafe}; -use std::thread::{self, JoinHandle}; +use std::{ + thread::{self, JoinHandle}, + thread_local, +}; use crate::executor::FallibleTask; use concurrent_queue::ConcurrentQueue; use futures_lite::FutureExt; #[cfg(feature = "portable-atomic")] -use {alloc::boxed::Box, portable_atomic_util::Arc}; +use portable_atomic_util::Arc; #[cfg(not(feature = "portable-atomic"))] use alloc::sync::Arc; diff --git a/crates/bevy_transform/src/helper.rs b/crates/bevy_transform/src/helper.rs index 2911c1620a..75e9e313d3 100644 --- a/crates/bevy_transform/src/helper.rs +++ b/crates/bevy_transform/src/helper.rs @@ -80,6 +80,7 @@ pub enum ComputeGlobalTransformError { #[cfg(test)] mod tests { + use alloc::{vec, vec::Vec}; use core::f32::consts::TAU; use bevy_app::App; diff --git a/crates/bevy_transform/src/lib.rs b/crates/bevy_transform/src/lib.rs index d9b67f7cfc..b8e08c2c1b 100644 --- a/crates/bevy_transform/src/lib.rs +++ b/crates/bevy_transform/src/lib.rs @@ -4,7 +4,10 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] + +#[cfg(feature = "std")] +extern crate std; #[cfg(feature = "alloc")] extern crate alloc; diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index f41fc50bd3..e3f544d865 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -186,6 +186,7 @@ unsafe fn propagate_recursive( #[cfg(test)] mod test { + use alloc::vec; use bevy_app::prelude::*; use bevy_ecs::{prelude::*, world::CommandQueue}; use bevy_math::{vec3, Vec3}; diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index fea65f11ed..b4c224d94b 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -1,18 +1,17 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![expect( - unsafe_code, - reason = "Some utilities, such as cells, require unsafe code." -)] #![doc( html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! General utilities for first-party [Bevy] engine crates. //! //! [Bevy]: https://bevyengine.org/ +#[cfg(feature = "std")] +extern crate std; + #[cfg(feature = "alloc")] extern crate alloc; @@ -367,6 +366,10 @@ impl OnDrop { impl Drop for OnDrop { fn drop(&mut self) { + #![expect( + unsafe_code, + reason = "Taking from a ManuallyDrop requires unsafe code." + )] // SAFETY: We may move out of `self`, since this instance can never be observed after it's dropped. let callback = unsafe { ManuallyDrop::take(&mut self.callback) }; callback(); diff --git a/crates/bevy_utils/src/parallel_queue.rs b/crates/bevy_utils/src/parallel_queue.rs index 01377c7573..f9c4c66ca0 100644 --- a/crates/bevy_utils/src/parallel_queue.rs +++ b/crates/bevy_utils/src/parallel_queue.rs @@ -1,6 +1,4 @@ -#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::vec::Vec; - use core::{cell::RefCell, ops::DerefMut}; use thread_local::ThreadLocal; diff --git a/crates/bevy_utils/src/synccell.rs b/crates/bevy_utils/src/synccell.rs index 628fb2756d..557555d826 100644 --- a/crates/bevy_utils/src/synccell.rs +++ b/crates/bevy_utils/src/synccell.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "SyncCell requires unsafe code.")] + //! A reimplementation of the currently unstable [`std::sync::Exclusive`] //! //! [`std::sync::Exclusive`]: https://doc.rust-lang.org/nightly/std/sync/struct.Exclusive.html diff --git a/crates/bevy_utils/src/syncunsafecell.rs b/crates/bevy_utils/src/syncunsafecell.rs index e447f71226..0a4e427fe4 100644 --- a/crates/bevy_utils/src/syncunsafecell.rs +++ b/crates/bevy_utils/src/syncunsafecell.rs @@ -1,3 +1,5 @@ +#![expect(unsafe_code, reason = "SyncUnsafeCell requires unsafe code.")] + //! A reimplementation of the currently unstable [`std::cell::SyncUnsafeCell`] //! //! [`std::cell::SyncUnsafeCell`]: https://doc.rust-lang.org/nightly/std/cell/struct.SyncUnsafeCell.html diff --git a/crates/bevy_window/src/lib.rs b/crates/bevy_window/src/lib.rs index a4c7ccc655..8ef4cb9c0c 100644 --- a/crates/bevy_window/src/lib.rs +++ b/crates/bevy_window/src/lib.rs @@ -3,7 +3,7 @@ html_logo_url = "https://bevyengine.org/assets/icon.png", html_favicon_url = "https://bevyengine.org/assets/icon.png" )] -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] //! `bevy_window` provides a platform-agnostic interface for windowing in Bevy. //! @@ -12,6 +12,9 @@ //! The [`WindowPlugin`] sets up some global window-related parameters and //! is part of the [`DefaultPlugins`](https://docs.rs/bevy/latest/bevy/struct.DefaultPlugins.html). +#[cfg(feature = "std")] +extern crate std; + extern crate alloc; use alloc::sync::Arc; diff --git a/tools/example-showcase/window-settings-wasm.patch b/tools/example-showcase/window-settings-wasm.patch index f5d51baa3e..56d16cde96 100644 --- a/tools/example-showcase/window-settings-wasm.patch +++ b/tools/example-showcase/window-settings-wasm.patch @@ -10,7 +10,7 @@ index ccc861a78..0cae580cd 100644 + fit_canvas_to_parent: true, prevent_default_event_handling: true, - canvas: None, -+ canvas: Some("#bevy".to_string()), ++ canvas: Some("#bevy".to_owned()), window_theme: None, visible: true, skip_taskbar: false,