Skip to content

Commit 2946151

Browse files
james7132exjam
authored andcommitted
Fail to compile on 16-bit platforms (bevyengine#4736)
# Objective `bevy_ecs` assumes that `u32 as usize` is a lossless operation and in a few cases relies on this for soundness and correctness. The only platforms that Rust compiles to where this invariant is broken are 16-bit systems. A very clear example of this behavior is in the SparseSetIndex impl for Entity, where it converts a u32 into a usize to act as an index. If usize is 16-bit, the conversion will overflow and provide the caller with the wrong index. This can easily result in previously unforseen aliased mutable borrows (i.e. Query::get_many_mut). ## Solution Explicitly fail compilation on 16-bit platforms instead of introducing UB. Properly supporting 16-bit systems will likely need a workable use case first. --- ## Changelog Removed: Ability to compile `bevy_ecs` on 16-bit platforms. ## Migration Guide `bevy_ecs` will now explicitly fail to compile on 16-bit platforms. If this is required, there is currently no alternative. Please file an issue (https://github.com/bevyengine/bevy/issues) to help detail your use case.
1 parent 56b2690 commit 2946151

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

crates/bevy_ecs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![doc = include_str!("../README.md")]
22

3+
#[cfg(target_pointer_width = "16")]
4+
compile_error!("bevy_ecs cannot safely compile for a 16-bit platform.");
5+
36
pub mod archetype;
47
pub mod bundle;
58
pub mod change_detection;

0 commit comments

Comments
 (0)