Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/bevyengine/bevy"
documentation = "https://docs.rs/bevy"
rust-version = "1.88.0"
rust-version = "1.89.0"
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 sure if it makes sense to bump the MSRV just for this small change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I personally don't see the harm: without_provenance() is much simpler than what we had before, and it gives Miri extra insight into what we're doing with the pointer. Bevy's MSRV policy has made it clear that we'll take advantage of newly-stabilized features if they're useful to us, so I feel it's fair game.


[workspace]
resolver = "2"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["ecs", "game", "bevy"]
categories = ["game-engines", "data-structures"]
rust-version = "1.86.0"
rust-version = "1.89.0"

[features]
default = ["std", "bevy_reflect", "async_executor", "backtrace"]
Expand Down
20 changes: 9 additions & 11 deletions crates/bevy_ecs/src/component/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,18 @@ pub fn component_clone_via_reflect(source: &SourceComponent, ctx: &mut Component
// Try to clone using ReflectFromReflect
if let Some(reflect_from_reflect) =
registry.get_type_data::<bevy_reflect::ReflectFromReflect>(type_id)
{
if let Some(mut component) =
&& let Some(mut component) =
reflect_from_reflect.from_reflect(source_component_reflect.as_partial_reflect())
{
if let Some(reflect_component) =
registry.get_type_data::<crate::reflect::ReflectComponent>(type_id)
{
if let Some(reflect_component) =
registry.get_type_data::<crate::reflect::ReflectComponent>(type_id)
{
reflect_component.map_entities(&mut *component, ctx.entity_mapper());
}
drop(registry);

ctx.write_target_component_reflect(component);
return;
reflect_component.map_entities(&mut *component, ctx.entity_mapper());
}
drop(registry);

ctx.write_target_component_reflect(component);
return;
}
// Else, try to clone using ReflectDefault
if let Some(reflect_default) =
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/entity/clone_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,11 @@ impl OptOut {
#[inline]
fn filter_deny(&mut self, id: ComponentId, world: &World) {
self.deny.insert(id);
if self.attach_required_by_components {
if let Some(required_by) = world.components().get_required_by(id) {
self.deny.extend(required_by.iter());
};
}
if self.attach_required_by_components
&& let Some(required_by) = world.components().get_required_by(id)
{
self.deny.extend(required_by.iter());
};
}
}

Expand Down
32 changes: 16 additions & 16 deletions crates/bevy_ecs/src/error/bevy_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ mod tests {

// On mac backtraces can start with Backtrace::create
let mut skip = false;
if let Some(line) = lines.peek() {
if &line[6..] == "std::backtrace::Backtrace::create" {
skip = true;
}
if let Some(line) = lines.peek()
&& &line[6..] == "std::backtrace::Backtrace::create"
{
skip = true;
}

if skip {
Expand All @@ -212,10 +212,10 @@ mod tests {
let line = lines.next().unwrap();
assert_eq!(&line[6..], expected);
let mut skip = false;
if let Some(line) = lines.peek() {
if line.starts_with(" at") {
skip = true;
}
if let Some(line) = lines.peek()
&& line.starts_with(" at")
{
skip = true;
}

if skip {
Expand All @@ -225,19 +225,19 @@ mod tests {

// on linux there is a second call_once
let mut skip = false;
if let Some(line) = lines.peek() {
if &line[6..] == "core::ops::function::FnOnce::call_once" {
skip = true;
}
if let Some(line) = lines.peek()
&& &line[6..] == "core::ops::function::FnOnce::call_once"
{
skip = true;
}
if skip {
lines.next().unwrap();
}
let mut skip = false;
if let Some(line) = lines.peek() {
if line.starts_with(" at") {
skip = true;
}
if let Some(line) = lines.peek()
&& line.starts_with(" at")
{
skip = true;
}

if skip {
Expand Down
24 changes: 12 additions & 12 deletions crates/bevy_ecs/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ impl World {
&& observers.entity_component_observers.is_empty()
{
cache.component_observers.remove(component);
if let Some(flag) = Observers::is_archetype_cached(event_key) {
if let Some(by_component) = archetypes.by_component.get(component) {
for archetype in by_component.keys() {
let archetype = &mut archetypes.archetypes[archetype.index()];
if archetype.contains(*component) {
let no_longer_observed = archetype
.iter_components()
.all(|id| !cache.component_observers.contains_key(&id));

if no_longer_observed {
archetype.flags.set(flag, false);
}
if let Some(flag) = Observers::is_archetype_cached(event_key)
&& let Some(by_component) = archetypes.by_component.get(component)
{
for archetype in by_component.keys() {
let archetype = &mut archetypes.archetypes[archetype.index()];
if archetype.contains(*component) {
let no_longer_observed = archetype
.iter_components()
.all(|id| !cache.component_observers.contains_key(&id));

if no_longer_observed {
archetype.flags.set(flag, false);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3214,10 +3214,10 @@ mod tests {

fn system(query: Query<EntityRef>) {
for entity_ref in &query {
if let Some(c) = entity_ref.get_ref::<C>() {
if !c.is_added() {
panic!("Expected C to be added");
}
if let Some(c) = entity_ref.get_ref::<C>()
&& !c.is_added()
{
panic!("Expected C to be added");
}
}
}
Expand Down
41 changes: 20 additions & 21 deletions crates/bevy_ecs/src/relationship/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,28 +188,27 @@ pub trait Relationship: Component + Sized {
}
}
let target_entity = world.entity(entity).get::<Self>().unwrap().get();
if let Ok(mut target_entity_mut) = world.get_entity_mut(target_entity) {
if let Some(mut relationship_target) =
if let Ok(mut target_entity_mut) = world.get_entity_mut(target_entity)
&& let Some(mut relationship_target) =
target_entity_mut.get_mut::<Self::RelationshipTarget>()
{
relationship_target.collection_mut_risky().remove(entity);
if relationship_target.len() == 0 {
let command = |mut entity: EntityWorldMut| {
// this "remove" operation must check emptiness because in the event that an identical
// relationship is inserted on top, this despawn would result in the removal of that identical
// relationship ... not what we want!
if entity
.get::<Self::RelationshipTarget>()
.is_some_and(RelationshipTarget::is_empty)
{
entity.remove::<Self::RelationshipTarget>();
}
};

world
.commands()
.queue_silenced(command.with_entity(target_entity));
}
{
relationship_target.collection_mut_risky().remove(entity);
if relationship_target.len() == 0 {
let command = |mut entity: EntityWorldMut| {
// this "remove" operation must check emptiness because in the event that an identical
// relationship is inserted on top, this despawn would result in the removal of that identical
// relationship ... not what we want!
if entity
.get::<Self::RelationshipTarget>()
.is_some_and(RelationshipTarget::is_empty)
{
entity.remove::<Self::RelationshipTarget>();
}
};

world
.commands()
.queue_silenced(command.with_entity(target_entity));
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_ecs/src/storage/blob_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ impl BlobArray {
) -> Self {
if capacity == 0 {
let align = NonZeroUsize::new(item_layout.align()).expect("alignment must be > 0");
let data = bevy_ptr::dangling_with_align(align);

// Create a dangling pointer with the given alignment.
let data = NonNull::without_provenance(align);

Self {
item_layout,
drop: drop_fn,
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ where
// Note that the `downcast_mut` check is based on the static type,
// and can be optimized out after monomorphization.
let any: &mut dyn Any = &mut value;
if let Some(err) = any.downcast_mut::<SystemParamValidationError>() {
if err.skipped {
return Self::Skipped(core::mem::replace(err, SystemParamValidationError::EMPTY));
}
if let Some(err) = any.downcast_mut::<SystemParamValidationError>()
&& err.skipped
{
return Self::Skipped(core::mem::replace(err, SystemParamValidationError::EMPTY));
}
Self::Failed(From::from(value))
}
Expand Down
11 changes: 0 additions & 11 deletions crates/bevy_ptr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use core::{
fmt::{self, Debug, Formatter, Pointer},
marker::PhantomData,
mem::{self, ManuallyDrop, MaybeUninit},
num::NonZeroUsize,
ops::{Deref, DerefMut},
ptr::{self, NonNull},
};
Expand Down Expand Up @@ -1102,16 +1101,6 @@ impl<'a, T> From<&'a [T]> for ThinSlicePtr<'a, T> {
}
}

/// Creates a dangling pointer with specified alignment.
/// See [`NonNull::dangling`].
pub const fn dangling_with_align(align: NonZeroUsize) -> NonNull<u8> {
debug_assert!(align.is_power_of_two(), "Alignment must be power of two.");
// SAFETY: The pointer will not be null, since it was created
// from the address of a `NonZero<usize>`.
// TODO: use https://doc.rust-lang.org/std/ptr/struct.NonNull.html#method.with_addr once stabilized
unsafe { NonNull::new_unchecked(ptr::null_mut::<u8>().wrapping_add(align.get())) }
}

mod private {
use core::cell::UnsafeCell;

Expand Down
14 changes: 14 additions & 0 deletions release-content/migration-guides/remove_dangling_with_align.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Remove `bevy::ptr::dangling_with_align()`
pull_requests: [21822]
---

`bevy::ptr::dangling_with_align()` has been removed. Use `NonNull::without_provenance()` instead:

```rust
// 0.17
let ptr = dangling_with_align(align);

// 0.18
let ptr = NonNull::without_provenance(align);
```
Loading