Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/bundle/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

//! Types for handling [`Bundle`]s.
//!
//! This module contains the [`Bundle`] trait and some other helper types.
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/entity/clone_entities.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

use crate::{
archetype::Archetype,
bundle::{Bundle, BundleRemover, InsertMode},
Expand Down
4 changes: 0 additions & 4 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]
#![doc = include_str!("../README.md")]
#![cfg_attr(
any(docsrs, docsrs_dep),
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

//! Contains APIs for retrieving component data from the world.

mod access;
Expand Down
15 changes: 9 additions & 6 deletions crates/bevy_ecs/src/schedule/executor/multi_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,15 @@ impl ExecutorState {
}

#[cfg(feature = "hotpatching")]
let hotpatch_tick = context
.environment
.world_cell
.get_resource_ref::<HotPatchChanges>()
.map(|r| r.last_changed())
.unwrap_or_default();
// SAFETY: No system should mutate `HotPatchChanges`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the best safety, but hotpatching is already pretty unsafe and the resource only exists when hotpatching is active.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really convinced by this safety doc. "Should" seems to imply that HotPatchChanges can be mutated while this reference is held.

The safety doc should prove that the unsafe operation is in-fact safe. For example, if HotPatchChanges cannot be mutated during this, then the safety doc should mention as such. Same with if it's the caller's responsibility to uphold that safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not safe. A system could actually try to mutate HotPatchChanges. But I'm don't think it's worth making this safe. We'd have to check if any system that is added tries to mutate HotPatchChanges. But they could only make a system that mutates HotPatchChanges when the hotpatching feature is enabled. Overall hotpatching is probably UB, so if someone ships with hotpatching enabled it's already a problem.

Copy link
Contributor

@LikeLakers2 LikeLakers2 Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not safe.

Then the safety doc should be removed, as it's not documenting the safety of the unsafe {} block.

And actually, if we know this to be unsafe, then we should document it as such. This ensures a couple things:

  1. Users perusing the code won't be confused into thinking that thus unsafe operation is somehow safe.
  2. Future safety-related PRs will know that this code is unsafe, giving them an idea of what they're getting into.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use an expect annotation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use an expect annotation here?

Yeah, that might be more clear.

let hotpatch_tick = unsafe {
context
.environment
.world_cell
.get_resource_ref::<HotPatchChanges>()
}
.map(|r| r.last_changed())
.unwrap_or_default();

// can't borrow since loop mutably borrows `self`
let mut ready_systems = core::mem::take(&mut self.ready_systems_copy);
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

//! Storage layouts for ECS data.
//!
//! This module implements the low-level collections that store data in a [`World`]. These all offer minimal and often
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/system/combinator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

use alloc::{format, vec::Vec};
use bevy_utils::prelude::DebugName;
use core::marker::PhantomData;
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

pub use crate::change_detection::{NonSend, NonSendMut, Res, ResMut};
use crate::{
archetype::Archetypes,
Expand Down
5 changes: 5 additions & 0 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![expect(
unsafe_op_in_unsafe_fn,
reason = "See #11590. To be removed once all applicable unsafe code has an unsafe block with a safety comment."
)]

//! Defines the [`World`] and APIs for accessing it directly.

pub(crate) mod command_queue;
Expand Down