Remove unsound Clone impl for EntityMutExcept (#17032)

# Objective

`EntityMutExcept` can currently be cloned, which can easily violate
aliasing rules.

## Solution

- Remove the `Clone` impl for `EntityMutExcept`
- Also manually derived `Clone` impl for `EntityRefExcept` so that `B:
Clone` isn't required, and also impl'd `Copy`

## Testing

Compile failure tests would be good for this, but I'm not exactly sure
how to set that up.

## Migration Guide

- `EntityMutExcept` can no-longer be cloned, as this violates Rust's
memory safety rules.
This commit is contained in:
Christian Hughes 2024-12-29 23:17:46 -06:00 committed by GitHub
parent 79a367db16
commit b09bbfa905
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3435,7 +3435,6 @@ pub enum TryFromFilteredError {
/// Provides read-only access to a single entity and all its components, save
/// for an explicitly-enumerated set.
#[derive(Clone)]
pub struct EntityRefExcept<'w, B>
where
B: Bundle,
@ -3521,6 +3520,14 @@ where
}
}
impl<B: Bundle> Clone for EntityRefExcept<'_, B> {
fn clone(&self) -> Self {
*self
}
}
impl<B: Bundle> Copy for EntityRefExcept<'_, B> {}
impl<B: Bundle> PartialEq for EntityRefExcept<'_, B> {
fn eq(&self, other: &Self) -> bool {
self.entity() == other.entity()
@ -3567,7 +3574,6 @@ unsafe impl<B: Bundle> TrustedEntityBorrow for EntityRefExcept<'_, B> {}
/// queries that might match entities that this query also matches. If you don't
/// need access to all components, prefer a standard query with a
/// [`crate::query::Without`] filter.
#[derive(Clone)]
pub struct EntityMutExcept<'w, B>
where
B: Bundle,