Skip to content

Commit f6b5150

Browse files
committed
move expects to function body
1 parent f2f4a2a commit f6b5150

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

examples/stress_tests/many_components.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rand::prelude::{Rng, SeedableRng, SliceRandom};
3131
use rand_chacha::ChaCha8Rng;
3232
use std::{alloc::Layout, mem::ManuallyDrop, num::Wrapping};
3333

34+
#[expect(unsafe_code, reason = "Reading dynamic components requires unsafe")]
3435
// A simple system that matches against several components and does some menial calculation to create
3536
// some non-trivial load.
3637
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
4849
// find the value of the component
4950
let ptr = filtered_entity.get_by_id(*component_id).unwrap();
5051

51-
#[expect(
52-
unsafe_code,
53-
reason = "Used to calculate Faulhaber's formula, per the comment above"
54-
)]
5552
// SAFETY: All components have a u8 layout
5653
let value: u8 = unsafe { *ptr.deref::<u8>() };
5754

@@ -68,10 +65,6 @@ fn base_system(access_components: In<Vec<ComponentId>>, mut query: Query<Filtere
6865
// we assign this value to all the components we can write to
6966
for component_id in &access_components.0 {
7067
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-
)]
7568
// SAFETY: All components have a u8 layout
7669
unsafe {
7770
let mut value = ptr.with_type::<u8>();
@@ -82,6 +75,7 @@ fn base_system(access_components: In<Vec<ComponentId>>, mut query: Query<Filtere
8275
}
8376
}
8477

78+
#[expect(unsafe_code, reason = "Using dynamic components requires unsafe")]
8579
fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
8680
let mut rng = ChaCha8Rng::seed_from_u64(42);
8781
let mut app = App::default();
@@ -91,7 +85,6 @@ fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
9185
let component_ids: Vec<ComponentId> = (1..=num_components)
9286
.map(|i| {
9387
world.register_component_with_descriptor(
94-
#[expect(unsafe_code, reason = "Used to register a bunch of fake components")]
9588
// SAFETY:
9689
// * We don't implement a drop function
9790
// * u8 is Sync and Send
@@ -152,16 +145,12 @@ fn stress_test(num_entities: u32, num_components: u32, num_systems: u32) {
152145
// SAFETY:
153146
// * We don't read/write `values` binding after this and values are `ManuallyDrop`,
154147
// 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() }
159149
})
160150
.collect();
161151
// SAFETY:
162152
// * component_id's are from the same world
163153
// * `values` was initialized above, so references are valid
164-
#[allow(unsafe_code)]
165154
unsafe {
166155
entity.insert_by_ids(&components, ptrs.into_iter());
167156
}

0 commit comments

Comments
 (0)