Skip to content

Commit 6f2cc0b

Browse files
relax Sized bounds around change detection types (#5917)
# Objective I wanted to run the code ```rust let reflect_resource: ReflectResource = ...; let value: Mut<dyn Reflect> = reflect_resource.reflect(world); value.deref(); // ^ ERROR: deref method doesn't exist because `dyn Reflect` doesnt satisfy `: Sized`. ``` ## Solution Relax `Sized` bounds in all the methods and trait implementations for `Mut` and friends.
1 parent ca3fa9d commit 6f2cc0b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/bevy_ecs/src/change_detection.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub trait DetectChanges {
4646
/// The type contained within this smart pointer
4747
///
4848
/// For example, for `Res<T>` this would be `T`.
49-
type Inner;
49+
type Inner: ?Sized;
5050

5151
/// Returns `true` if this value was added after the system last ran.
5252
fn is_added(&self) -> bool;
@@ -90,7 +90,7 @@ pub trait DetectChanges {
9090

9191
macro_rules! change_detection_impl {
9292
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
93-
impl<$($generics),* $(: $traits)?> DetectChanges for $name<$($generics),*> {
93+
impl<$($generics),* : ?Sized $(+ $traits)?> DetectChanges for $name<$($generics),*> {
9494
type Inner = $target;
9595

9696
#[inline]
@@ -130,7 +130,7 @@ macro_rules! change_detection_impl {
130130
}
131131
}
132132

133-
impl<$($generics),* $(: $traits)?> Deref for $name<$($generics),*> {
133+
impl<$($generics),*: ?Sized $(+ $traits)?> Deref for $name<$($generics),*> {
134134
type Target = $target;
135135

136136
#[inline]
@@ -139,7 +139,7 @@ macro_rules! change_detection_impl {
139139
}
140140
}
141141

142-
impl<$($generics),* $(: $traits)?> DerefMut for $name<$($generics),*> {
142+
impl<$($generics),* : ?Sized $(+ $traits)?> DerefMut for $name<$($generics),*> {
143143
#[inline]
144144
fn deref_mut(&mut self) -> &mut Self::Target {
145145
self.set_changed();
@@ -165,7 +165,7 @@ macro_rules! change_detection_impl {
165165

166166
macro_rules! impl_into_inner {
167167
($name:ident < $( $generics:tt ),+ >, $target:ty, $($traits:ident)?) => {
168-
impl<$($generics),* $(: $traits)?> $name<$($generics),*> {
168+
impl<$($generics),* : ?Sized $(+ $traits)?> $name<$($generics),*> {
169169
/// Consume `self` and return a mutable reference to the
170170
/// contained value while marking `self` as "changed".
171171
#[inline]
@@ -179,12 +179,12 @@ macro_rules! impl_into_inner {
179179

180180
macro_rules! impl_debug {
181181
($name:ident < $( $generics:tt ),+ >, $($traits:ident)?) => {
182-
impl<$($generics),* $(: $traits)?> std::fmt::Debug for $name<$($generics),*>
182+
impl<$($generics),* : ?Sized $(+ $traits)?> std::fmt::Debug for $name<$($generics),*>
183183
where T: std::fmt::Debug
184184
{
185185
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
186186
f.debug_tuple(stringify!($name))
187-
.field(self.value)
187+
.field(&self.value)
188188
.finish()
189189
}
190190
}
@@ -209,7 +209,7 @@ pub(crate) struct Ticks<'a> {
209209
/// Panics when used as a [`SystemParam`](crate::system::SystemParam) if the resource does not exist.
210210
///
211211
/// Use `Option<ResMut<T>>` instead if the resource might not always exist.
212-
pub struct ResMut<'a, T: Resource> {
212+
pub struct ResMut<'a, T: ?Sized + Resource> {
213213
pub(crate) value: &'a mut T,
214214
pub(crate) ticks: Ticks<'a>,
215215
}
@@ -241,7 +241,7 @@ impl<'a, T: Resource> From<ResMut<'a, T>> for Mut<'a, T> {
241241
/// Panics when used as a `SystemParameter` if the resource does not exist.
242242
///
243243
/// Use `Option<NonSendMut<T>>` instead if the resource might not always exist.
244-
pub struct NonSendMut<'a, T: 'static> {
244+
pub struct NonSendMut<'a, T: ?Sized + 'static> {
245245
pub(crate) value: &'a mut T,
246246
pub(crate) ticks: Ticks<'a>,
247247
}

0 commit comments

Comments
 (0)