@@ -23,9 +23,9 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
2323 impl_generics,
2424 ty_generics,
2525 where_clause,
26- struct_has_world_lt ,
27- world_lt ,
28- state_lt ,
26+ struct_has_world_lifetime ,
27+ world_lifetime ,
28+ state_lifetime ,
2929 } = fetch_impl_tokens ( & ast) ;
3030
3131 // Fetch's HRTBs require this hack to make the implementation compile. I don't fully understand
@@ -34,9 +34,9 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
3434 // - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=da5e260a5c2f3e774142d60a199e854a (this fails)
3535 // - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=802517bb3d8f83c45ee8c0be360bb250 (this compiles)
3636 let mut fetch_generics = ast. generics . clone ( ) ;
37- fetch_generics. params . insert ( 0 , state_lt ) ;
38- if !struct_has_world_lt {
39- fetch_generics. params . insert ( 0 , world_lt ) ;
37+ fetch_generics. params . insert ( 0 , state_lifetime ) ;
38+ if !struct_has_world_lifetime {
39+ fetch_generics. params . insert ( 0 , world_lifetime ) ;
4040 }
4141 fetch_generics
4242 . params
@@ -46,7 +46,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
4646 ) ) ) ) ;
4747 let ( fetch_impl_generics, _, _) = fetch_generics. split_for_impl ( ) ;
4848 let mut fetch_generics = ast. generics . clone ( ) ;
49- if struct_has_world_lt {
49+ if struct_has_world_lifetime {
5050 * fetch_generics. params . first_mut ( ) . unwrap ( ) =
5151 GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'fetch" , Span :: call_site ( ) ) ) ) ;
5252 }
@@ -142,9 +142,9 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
142142 /// SAFETY: each item in the struct is read only
143143 unsafe impl #impl_generics #path:: query:: ReadOnlyFetch for #fetch_struct_name #ty_generics #where_clause { }
144144
145- // Statically checks that the safety guarantee holds true indeed . We need this to make
146- // sure that we don't compile ReadOnlyFetch if our struct contains nested WorldQuery
147- // that don't implement it.
145+ // Statically checks that the safety guarantee actually holds true. We need this to make
146+ // sure that we don't compile ` ReadOnlyFetch` if our struct contains nested ` WorldQuery`
147+ // members that don't implement it.
148148 #[ allow( dead_code) ]
149149 const _: ( ) = {
150150 fn assert_readonly<T : #path:: query:: ReadOnlyFetch >( ) { }
@@ -183,16 +183,20 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
183183 true #( && self . #field_idents. is_dense( ) ) *
184184 }
185185
186+ /// SAFETY: we call `set_archetype` for each member that implements `Fetch`
186187 #[ inline]
187188 unsafe fn set_archetype( & mut self , _state: & Self :: State , _archetype: & #path:: archetype:: Archetype , _tables: & #path:: storage:: Tables ) {
188189 #( self . #field_idents. set_archetype( & _state. #field_idents, _archetype, _tables) ; ) *
189190 }
190191
192+ /// SAFETY: we call `set_table` for each member that implements `Fetch`
191193 #[ inline]
192194 unsafe fn set_table( & mut self , _state: & Self :: State , _table: & #path:: storage:: Table ) {
193195 #( self . #field_idents. set_table( & _state. #field_idents, _table) ; ) *
194196 }
195197
198+ /// SAFETY: we call `table_fetch` for each member that implements `Fetch` or
199+ /// `table_filter_fetch` if it also implements `FilterFetch`.
196200 #[ inline]
197201 unsafe fn table_fetch( & mut self , _table_row: usize ) -> Self :: Item {
198202 use #path:: query:: FilterFetch ;
@@ -203,6 +207,8 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
203207 }
204208 }
205209
210+ /// SAFETY: we call `archetype_fetch` for each member that implements `Fetch` or
211+ /// `archetype_filter_fetch` if it also implements `FilterFetch`.
206212 #[ inline]
207213 unsafe fn archetype_fetch( & mut self , _archetype_index: usize ) -> Self :: Item {
208214 use #path:: query:: FilterFetch ;
@@ -214,7 +220,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
214220 }
215221 }
216222
217- // SAFETY: update_component_access and update_archetype_component_access are called for each item in the struct
223+ // SAFETY: ` update_component_access` and ` update_archetype_component_access` are called for each item in the struct
218224 unsafe impl #impl_generics #path:: query:: FetchState for #state_struct_name #ty_generics #where_clause {
219225 fn init( world: & mut #path:: world:: World ) -> Self {
220226 #state_struct_name {
@@ -260,9 +266,9 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
260266 impl_generics,
261267 ty_generics,
262268 where_clause,
263- struct_has_world_lt ,
264- world_lt ,
265- state_lt ,
269+ struct_has_world_lifetime ,
270+ world_lifetime ,
271+ state_lifetime ,
266272 } = fetch_impl_tokens ( & ast) ;
267273
268274 // Fetch's HRTBs require this hack to make the implementation compile. I don't fully understand
@@ -271,9 +277,9 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
271277 // - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=da5e260a5c2f3e774142d60a199e854a (this fails)
272278 // - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=802517bb3d8f83c45ee8c0be360bb250 (this compiles)
273279 let mut fetch_generics = ast. generics . clone ( ) ;
274- fetch_generics. params . insert ( 0 , state_lt ) ;
275- if !struct_has_world_lt {
276- fetch_generics. params . insert ( 0 , world_lt ) ;
280+ fetch_generics. params . insert ( 0 , state_lifetime ) ;
281+ if !struct_has_world_lifetime {
282+ fetch_generics. params . insert ( 0 , world_lifetime ) ;
277283 }
278284 fetch_generics
279285 . params
@@ -283,7 +289,7 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
283289 ) ) ) ) ;
284290 let ( fetch_impl_generics, _, _) = fetch_generics. split_for_impl ( ) ;
285291 let mut fetch_generics = ast. generics . clone ( ) ;
286- if struct_has_world_lt {
292+ if struct_has_world_lifetime {
287293 * fetch_generics. params . first_mut ( ) . unwrap ( ) =
288294 GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'fetch" , Span :: call_site ( ) ) ) ) ;
289295 }
@@ -410,6 +416,7 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
410416 tokens
411417}
412418
419+ // This struct is used to share common tokens between `Fetch` and `FilterFetch` implementations.
413420struct FetchImplTokens < ' a > {
414421 struct_name : Ident ,
415422 fetch_struct_name : Ident ,
@@ -418,26 +425,26 @@ struct FetchImplTokens<'a> {
418425 impl_generics : ImplGenerics < ' a > ,
419426 ty_generics : TypeGenerics < ' a > ,
420427 where_clause : Option < & ' a WhereClause > ,
421- struct_has_world_lt : bool ,
422- world_lt : GenericParam ,
423- state_lt : GenericParam ,
428+ struct_has_world_lifetime : bool ,
429+ world_lifetime : GenericParam ,
430+ state_lifetime : GenericParam ,
424431}
425432
426433fn fetch_impl_tokens ( ast : & DeriveInput ) -> FetchImplTokens {
427- let world_lt = ast. generics . params . first ( ) . and_then ( |param| match param {
434+ let world_lifetime = ast. generics . params . first ( ) . and_then ( |param| match param {
428435 lt @ GenericParam :: Lifetime ( _) => Some ( lt. clone ( ) ) ,
429436 _ => None ,
430437 } ) ;
431- let struct_has_world_lt = world_lt . is_some ( ) ;
432- let world_lt = world_lt . unwrap_or_else ( || {
438+ let struct_has_world_lifetime = world_lifetime . is_some ( ) ;
439+ let world_lifetime = world_lifetime . unwrap_or_else ( || {
433440 GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'world" , Span :: call_site ( ) ) ) )
434441 } ) ;
435- let state_lt =
442+ let state_lifetime =
436443 GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'state" , Span :: call_site ( ) ) ) ) ;
437444
438445 let mut fetch_trait_punctuated_lifetimes = Punctuated :: < _ , Token ! [ , ] > :: new ( ) ;
439- fetch_trait_punctuated_lifetimes. push ( world_lt . clone ( ) ) ;
440- fetch_trait_punctuated_lifetimes. push ( state_lt . clone ( ) ) ;
446+ fetch_trait_punctuated_lifetimes. push ( world_lifetime . clone ( ) ) ;
447+ fetch_trait_punctuated_lifetimes. push ( state_lifetime . clone ( ) ) ;
441448
442449 let ( impl_generics, ty_generics, where_clause) = ast. generics . split_for_impl ( ) ;
443450
@@ -453,9 +460,9 @@ fn fetch_impl_tokens(ast: &DeriveInput) -> FetchImplTokens {
453460 impl_generics,
454461 ty_generics,
455462 where_clause,
456- struct_has_world_lt ,
457- world_lt ,
458- state_lt ,
463+ struct_has_world_lifetime ,
464+ world_lifetime ,
465+ state_lifetime ,
459466 }
460467}
461468
0 commit comments