bevy/crates/bevy_reflect/derive/src
Zachary Harrold 0403948aa2
Remove Implicit std Prelude from no_std Crates (#17086)
# Background

In `no_std` compatible crates, there is often an `std` feature which
will allow access to the standard library. Currently, with the `std`
feature _enabled_, the
[`std::prelude`](https://doc.rust-lang.org/std/prelude/index.html) is
implicitly imported in all modules. With the feature _disabled_, instead
the [`core::prelude`](https://doc.rust-lang.org/core/prelude/index.html)
is implicitly imported. This creates a subtle and pervasive issue where
`alloc` items _may_ be implicitly included (if `std` is enabled), or
must be explicitly included (if `std` is not enabled).

# Objective

- Make the implicit imports for `no_std` crates consistent regardless of
what features are/not enabled.

## Solution

- Replace the `cfg_attr` "double negative" `no_std` attribute with
conditional compilation to _include_ `std` as an external crate.
```rust
// Before
#![cfg_attr(not(feature = "std"), no_std)]

// After
#![no_std]

#[cfg(feature = "std")]
extern crate std;
```
- Fix imports that are currently broken but are only now visible with
the above fix.

## Testing

- CI

## Notes

I had previously used the "double negative" version of `no_std` based on
general consensus that it was "cleaner" within the Rust embedded
community. However, this implicit prelude issue likely was considered
when forming this consensus. I believe the reason why is the items most
affected by this issue are provided by the `alloc` crate, which is
rarely used within embedded but extensively used within Bevy.
2025-01-03 01:58:43 +00:00
..
impls Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
attribute_parser.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
container_attributes.rs Replace map + unwrap_or(true) with is_none_or (#17070) 2024-12-31 20:17:03 +00:00
custom_attributes.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
derive_data.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
documentation.rs Rename bevy_reflect_derive folder to derive (#13269) 2024-05-07 07:55:32 +00:00
enum_utility.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
field_attributes.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
from_reflect.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
generics.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
ident.rs split bevy_reflect::derive::utilities into proper modules (#15354) 2024-09-22 14:24:14 +00:00
lib.rs bevy_reflect: Generic parameter info (#15475) 2024-09-30 17:58:37 +00:00
meta.rs Use one BevyManifest instance in proc macros (#16766) 2024-12-15 15:00:05 +00:00
reflect_opaque.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
registration.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
remote.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
result_sifter.rs split bevy_reflect::derive::utilities into proper modules (#15354) 2024-09-22 14:24:14 +00:00
serialization.rs Update hashbrown to 0.15 (#15801) 2024-12-10 19:45:50 +00:00
string_expr.rs Add no_std support to bevy_reflect (#16256) 2024-12-05 21:15:21 +00:00
struct_utility.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
trait_reflection.rs Use one BevyManifest instance in proc macros (#16766) 2024-12-15 15:00:05 +00:00
type_path.rs Rename bevy_reflect_derive folder to derive (#13269) 2024-05-07 07:55:32 +00:00
where_clause_options.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00