bevy/examples/ecs
James Liu 56bcbb0975
Forbid unsafe in most crates in the engine (#12684)
# Objective
Resolves #3824. `unsafe` code should be the exception, not the norm in
Rust. It's obviously needed for various use cases as it's interfacing
with platforms and essentially running the borrow checker at runtime in
the ECS, but the touted benefits of Bevy is that we are able to heavily
leverage Rust's safety, and we should be holding ourselves accountable
to that by minimizing our unsafe footprint.

## Solution
Deny `unsafe_code` workspace wide. Add explicit exceptions for the
following crates, and forbid it in almost all of the others.

* bevy_ecs - Obvious given how much unsafe is needed to achieve
performant results
* bevy_ptr - Works with raw pointers, even more low level than bevy_ecs.
 * bevy_render - due to needing to integrate with wgpu
 * bevy_window - due to needing to integrate with raw_window_handle
* bevy_utils - Several unsafe utilities used by bevy_ecs. Ideally moved
into bevy_ecs instead of made publicly usable.
 * bevy_reflect - Required for the unsafe type casting it's doing.
 * bevy_transform - for the parallel transform propagation
 * bevy_gizmos  - For the SystemParam impls it has.
* bevy_assets - To support reflection. Might not be required, not 100%
sure yet.
* bevy_mikktspace - due to being a conversion from a C library. Pending
safe rewrite.
* bevy_dynamic_plugin - Inherently unsafe due to the dynamic loading
nature.

Several uses of unsafe were rewritten, as they did not need to be using
them:

* bevy_text - a case of `Option::unchecked` could be rewritten as a
normal for loop and match instead of an iterator.
* bevy_color - the Pod/Zeroable implementations were replaceable with
bytemuck's derive macros.
2024-03-27 03:30:08 +00:00
..
component_change_detection.rs Remove useless single tuples and trailing commas (#9720) 2023-09-08 21:46:54 +00:00
component_hooks.rs Remove ComponentStorage and associated types (#12311) 2024-03-05 15:54:52 +00:00
custom_query_param.rs Rename WorldQueryData & WorldQueryFilter to QueryData & QueryFilter (#10779) 2023-12-12 19:45:50 +00:00
custom_schedule.rs Add custom schedule example (#11527) 2024-01-25 17:51:53 +00:00
dynamic.rs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
ecs_guide.rs Rephrase comment about Local<T> for clarity. (Adopted) (#11129) 2024-02-01 09:42:44 +00:00
event.rs Refactor EventReader::iter to read (#9631) 2023-08-30 14:20:03 +00:00
fixed_timestep.rs Unify FixedTime and Time while fixing several problems (#8964) 2023-10-16 01:57:55 +00:00
generic_system.rs Add insert_state to App. (#11043) 2023-12-21 14:09:24 +00:00
hierarchy.rs Fix green colors becoming darker in various examples (#12328) 2024-03-05 23:42:03 +00:00
iter_combinations.rs Adding explanation to seeded rng used in examples (#12593) 2024-03-26 19:40:18 +00:00
nondeterministic_system_order.rs Fix non-functional nondeterministic_system_order example (#10719) 2023-11-25 21:13:35 +00:00
one_shot_systems.rs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
parallel_query.rs Adding explanation to seeded rng used in examples (#12593) 2024-03-26 19:40:18 +00:00
removal_detection.rs Migrate from LegacyColor to bevy_color::Color (#12163) 2024-02-29 19:35:12 +00:00
run_conditions.rs Simplify conditions (#11316) 2024-01-13 13:22:17 +00:00
send_and_receive_events.rs fix some typos (#12038) 2024-02-22 18:55:22 +00:00
startup_system.rs Schedule-First: the new and improved add_systems (#8079) 2023-03-18 01:45:34 +00:00
state.rs Decouple BackgroundColor from UiImage (#11165) 2024-03-03 21:35:50 +00:00
system_closure.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
system_param.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
system_piping.rs Add support for updating the tracing subscriber in LogPlugin (#10822) 2024-01-15 15:26:13 +00:00
system_stepping.rs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00