Add FromWorld bound to T in Local<T> (#5481)
				
					
				
			# Objective Currently, actually using a `Local` on a system requires that it be `T: FromWorld`, but that requirement is only expressed on the `SystemParam` machinery, which leads to the confusing error message for when the user attempts to add an invalid system. By adding these bounds to `Local` directly, it improves clarity on usage and semantics. ## Solution - Add `T: FromWorld` bound to `Local`'s definition ## Migration Guide - It might be possible for references to `Local`s without `T: FromWorld` to exist, but these should be exceedingly rare and probably dead code. In the event that one of these is encountered, the easiest solutions are to delete the code or wrap the inner `T` in an `Option` to allow it to be default constructed to `None`.
This commit is contained in:
		
							parent
							
								
									bf085ee1d2
								
							
						
					
					
						commit
						f3b5bf029c
					
				| @ -640,12 +640,12 @@ impl<'w, 's> SystemParamFetch<'w, 's> for WorldState { | |||||||
| /// // .add_system(reset_to_system(my_config))
 | /// // .add_system(reset_to_system(my_config))
 | ||||||
| /// # assert_is_system(reset_to_system(Config(10)));
 | /// # assert_is_system(reset_to_system(Config(10)));
 | ||||||
| /// ```
 | /// ```
 | ||||||
| pub struct Local<'a, T: Resource>(&'a mut T); | pub struct Local<'a, T: Resource + FromWorld>(&'a mut T); | ||||||
| 
 | 
 | ||||||
| // SAFETY: Local only accesses internal state
 | // SAFETY: Local only accesses internal state
 | ||||||
| unsafe impl<T: Resource> ReadOnlySystemParamFetch for LocalState<T> {} | unsafe impl<T: Resource> ReadOnlySystemParamFetch for LocalState<T> {} | ||||||
| 
 | 
 | ||||||
| impl<'a, T: Resource> Debug for Local<'a, T> | impl<'a, T: Resource + FromWorld> Debug for Local<'a, T> | ||||||
| where | where | ||||||
|     T: Debug, |     T: Debug, | ||||||
| { | { | ||||||
| @ -654,7 +654,7 @@ where | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, T: Resource> Deref for Local<'a, T> { | impl<'a, T: Resource + FromWorld> Deref for Local<'a, T> { | ||||||
|     type Target = T; |     type Target = T; | ||||||
| 
 | 
 | ||||||
|     #[inline] |     #[inline] | ||||||
| @ -663,7 +663,7 @@ impl<'a, T: Resource> Deref for Local<'a, T> { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a, T: Resource> DerefMut for Local<'a, T> { | impl<'a, T: Resource + FromWorld> DerefMut for Local<'a, T> { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn deref_mut(&mut self) -> &mut Self::Target { |     fn deref_mut(&mut self) -> &mut Self::Target { | ||||||
|         self.0 |         self.0 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 PROMETHIA-27
						PROMETHIA-27