bevy/crates/bevy_render/src
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
..
batching Disentangle bevy_utils/bevy_core's reexported dependencies (#12313) 2024-03-07 02:30:15 +00:00
camera Reflect default in some types on bevy_render (#12580) 2024-03-19 22:50:17 +00:00
diagnostic Fix CI for wasm atomics (#12730) 2024-03-26 14:26:21 +00:00
mesh Support calculating normals for indexed meshes (#11654) 2024-03-25 19:09:24 +00:00
primitives Reflect default in some types on bevy_render (#12580) 2024-03-19 22:50:17 +00:00
render_graph Replace bevy_log's tracing reexport with bevy_utils' (#12254) 2024-03-02 18:38:04 +00:00
render_phase Add pipeline statistics (#9135) 2024-03-17 20:29:35 +00:00
render_resource Get Bevy building for WebAssembly with multithreading (#12205) 2024-03-25 19:10:18 +00:00
renderer Get Bevy building for WebAssembly with multithreading (#12205) 2024-03-25 19:10:18 +00:00
texture Removed Into<AssedId<T>> for Handle<T> as mentioned in #12600 (#12655) 2024-03-22 20:26:12 +00:00
view Get Bevy building for WebAssembly with multithreading (#12205) 2024-03-25 19:10:18 +00:00
alpha.rs Move AlphaMode into bevy_render (#12012) 2024-02-21 19:34:10 +00:00
deterministic.rs Option to enable deterministic rendering (#11248) 2024-01-09 00:46:01 +00:00
extract_component.rs Revert rendering-related associated type name changes (#11027) 2024-01-22 15:01:55 +00:00
extract_instances.rs Move EntityHash related types into bevy_ecs (#11498) 2024-02-12 15:02:24 +00:00
extract_param.rs Enable the unsafe_op_in_unsafe_fn lint (#11591) 2024-01-28 23:18:11 +00:00
extract_resource.rs Replace bevy_log's tracing reexport with bevy_utils' (#12254) 2024-03-02 18:38:04 +00:00
globals.rs Reflect default in some types on bevy_render (#12580) 2024-03-19 22:50:17 +00:00
globals.wgsl Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
gpu_component_array_buffer.rs Reorder render sets, refactor bevy_sprite to take advantage (#9236) 2023-08-27 14:33:49 +00:00
lib.rs Forbid unsafe in most crates in the engine (#12684) 2024-03-27 03:30:08 +00:00
maths.wgsl Add support for KHR_texture_transform (#11904) 2024-02-21 01:11:28 +00:00
pipelined_rendering.rs Simplified backtraces (#12305) 2024-03-10 12:18:59 +00:00
render_asset.rs reflect: remove manual Reflect impls which could be handled by macros (#12596) 2024-03-23 01:45:00 +00:00
settings.rs Update to wgpu 0.19 and raw-window-handle 0.6 (#11280) 2024-01-26 18:14:21 +00:00
spatial_bundle.rs Implement Clone for VisibilityBundle and SpatialBundle (#10394) 2023-11-07 21:25:00 +00:00