Skip to content

Commit ffc66f1

Browse files
authored
Move allow unsafe_op_in_unsafe_fn to module level in bevy_ecs (#22134)
# Objective - narrow the scope of the expect unsafe_op_in_unsafe_fn, so we can progressively remove them. ## Testing - cargo check showed no warnings
1 parent 2e45788 commit ffc66f1

File tree

9 files changed

+45
-12
lines changed

9 files changed

+45
-12
lines changed

crates/bevy_ecs/src/bundle/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
//! Types for handling [`Bundle`]s.
27
//!
38
//! This module contains the [`Bundle`] trait and some other helper types.

crates/bevy_ecs/src/entity/clone_entities.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
use crate::{
27
archetype::Archetype,
38
bundle::{Bundle, BundleRemover, InsertMode},

crates/bevy_ecs/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
#![expect(
2-
unsafe_op_in_unsafe_fn,
3-
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4-
)]
51
#![doc = include_str!("../README.md")]
62
#![cfg_attr(
73
any(docsrs, docsrs_dep),

crates/bevy_ecs/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
//! Contains APIs for retrieving component data from the world.
27
38
mod access;

crates/bevy_ecs/src/schedule/executor/multi_threaded.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,21 @@ impl ExecutorState {
448448
}
449449

450450
#[cfg(feature = "hotpatching")]
451-
let hotpatch_tick = context
452-
.environment
453-
.world_cell
454-
.get_resource_ref::<HotPatchChanges>()
455-
.map(|r| r.last_changed())
456-
.unwrap_or_default();
451+
#[expect(
452+
clippy::undocumented_unsafe_blocks,
453+
reason = "This actually could result in UB if a system tries to mutate
454+
`HotPatchChanges`. We allow this as the resource only exists with the `hotpatching` feature.
455+
and `hotpatching` should never be enabled in release."
456+
)]
457+
#[cfg(feature = "hotpatching")]
458+
let hotpatch_tick = unsafe {
459+
context
460+
.environment
461+
.world_cell
462+
.get_resource_ref::<HotPatchChanges>()
463+
}
464+
.map(|r| r.last_changed())
465+
.unwrap_or_default();
457466

458467
// can't borrow since loop mutably borrows `self`
459468
let mut ready_systems = core::mem::take(&mut self.ready_systems_copy);

crates/bevy_ecs/src/storage/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
//! Storage layouts for ECS data.
27
//!
38
//! This module implements the low-level collections that store data in a [`World`]. These all offer minimal and often

crates/bevy_ecs/src/system/combinator.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ where
167167
input: SystemIn<S>,
168168
world: &mut PrivateUnsafeWorldCell,
169169
) -> Result<S::Out, RunSystemError> {
170-
#![deny(unsafe_op_in_unsafe_fn)]
171-
172170
// SAFETY: see comment on `Func::combine` call
173171
match (|| unsafe {
174172
system.validate_param_unsafe(world.0)?;

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
pub use crate::change_detection::{NonSend, NonSendMut, Res, ResMut};
27
use crate::{
38
archetype::Archetypes,

crates/bevy_ecs/src/world/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#![expect(
2+
unsafe_op_in_unsafe_fn,
3+
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
4+
)]
5+
16
//! Defines the [`World`] and APIs for accessing it directly.
27
38
pub(crate) mod command_queue;

0 commit comments

Comments
 (0)