@@ -31,6 +31,7 @@ use rand::prelude::{Rng, SeedableRng, SliceRandom};
31
31
use rand_chacha:: ChaCha8Rng ;
32
32
use std:: { alloc:: Layout , mem:: ManuallyDrop , num:: Wrapping } ;
33
33
34
+ #[ expect( unsafe_code, reason = "Reading dynamic components requires unsafe" ) ]
34
35
// A simple system that matches against several components and does some menial calculation to create
35
36
// some non-trivial load.
36
37
fn base_system ( access_components : In < Vec < ComponentId > > , mut query : Query < FilteredEntityMut > ) {
@@ -48,10 +49,6 @@ fn base_system(access_components: In<Vec<ComponentId>>, mut query: Query<Filtere
48
49
// find the value of the component
49
50
let ptr = filtered_entity. get_by_id ( * component_id) . unwrap ( ) ;
50
51
51
- #[ expect(
52
- unsafe_code,
53
- reason = "Used to calculate Faulhaber's formula, per the comment above"
54
- ) ]
55
52
// SAFETY: All components have a u8 layout
56
53
let value: u8 = unsafe { * ptr. deref :: < u8 > ( ) } ;
57
54
@@ -68,10 +65,6 @@ fn base_system(access_components: In<Vec<ComponentId>>, mut query: Query<Filtere
68
65
// we assign this value to all the components we can write to
69
66
for component_id in & access_components. 0 {
70
67
if let Some ( ptr) = filtered_entity. get_mut_by_id ( * component_id) {
71
- #[ expect(
72
- unsafe_code,
73
- reason = "Used to write a value to every component that we can write to."
74
- ) ]
75
68
// SAFETY: All components have a u8 layout
76
69
unsafe {
77
70
let mut value = ptr. with_type :: < u8 > ( ) ;
@@ -82,6 +75,7 @@ fn base_system(access_components: In<Vec<ComponentId>>, mut query: Query<Filtere
82
75
}
83
76
}
84
77
78
+ #[ expect( unsafe_code, reason = "Using dynamic components requires unsafe" ) ]
85
79
fn stress_test ( num_entities : u32 , num_components : u32 , num_systems : u32 ) {
86
80
let mut rng = ChaCha8Rng :: seed_from_u64 ( 42 ) ;
87
81
let mut app = App :: default ( ) ;
@@ -91,7 +85,6 @@ fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
91
85
let component_ids: Vec < ComponentId > = ( 1 ..=num_components)
92
86
. map ( |i| {
93
87
world. register_component_with_descriptor (
94
- #[ expect( unsafe_code, reason = "Used to register a bunch of fake components" ) ]
95
88
// SAFETY:
96
89
// * We don't implement a drop function
97
90
// * u8 is Sync and Send
@@ -152,16 +145,12 @@ fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
152
145
// SAFETY:
153
146
// * We don't read/write `values` binding after this and values are `ManuallyDrop`,
154
147
// so we have the right to drop/move the values
155
- #[ allow( unsafe_code) ]
156
- unsafe {
157
- PtrMut :: from ( value) . promote ( )
158
- }
148
+ unsafe { PtrMut :: from ( value) . promote ( ) }
159
149
} )
160
150
. collect ( ) ;
161
151
// SAFETY:
162
152
// * component_id's are from the same world
163
153
// * `values` was initialized above, so references are valid
164
- #[ allow( unsafe_code) ]
165
154
unsafe {
166
155
entity. insert_by_ids ( & components, ptrs. into_iter ( ) ) ;
167
156
}
0 commit comments