@@ -23,9 +23,9 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
23
23
impl_generics,
24
24
ty_generics,
25
25
where_clause,
26
- struct_has_world_lt ,
27
- world_lt ,
28
- state_lt ,
26
+ struct_has_world_lifetime ,
27
+ world_lifetime ,
28
+ state_lifetime ,
29
29
} = fetch_impl_tokens ( & ast) ;
30
30
31
31
// 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 {
34
34
// - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=da5e260a5c2f3e774142d60a199e854a (this fails)
35
35
// - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=802517bb3d8f83c45ee8c0be360bb250 (this compiles)
36
36
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 ) ;
40
40
}
41
41
fetch_generics
42
42
. params
@@ -46,7 +46,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
46
46
) ) ) ) ;
47
47
let ( fetch_impl_generics, _, _) = fetch_generics. split_for_impl ( ) ;
48
48
let mut fetch_generics = ast. generics . clone ( ) ;
49
- if struct_has_world_lt {
49
+ if struct_has_world_lifetime {
50
50
* fetch_generics. params . first_mut ( ) . unwrap ( ) =
51
51
GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'fetch" , Span :: call_site ( ) ) ) ) ;
52
52
}
@@ -142,9 +142,9 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
142
142
/// SAFETY: each item in the struct is read only
143
143
unsafe impl #impl_generics #path:: query:: ReadOnlyFetch for #fetch_struct_name #ty_generics #where_clause { }
144
144
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.
148
148
#[ allow( dead_code) ]
149
149
const _: ( ) = {
150
150
fn assert_readonly<T : #path:: query:: ReadOnlyFetch >( ) { }
@@ -183,16 +183,20 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
183
183
true #( && self . #field_idents. is_dense( ) ) *
184
184
}
185
185
186
+ /// SAFETY: we call `set_archetype` for each member that implements `Fetch`
186
187
#[ inline]
187
188
unsafe fn set_archetype( & mut self , _state: & Self :: State , _archetype: & #path:: archetype:: Archetype , _tables: & #path:: storage:: Tables ) {
188
189
#( self . #field_idents. set_archetype( & _state. #field_idents, _archetype, _tables) ; ) *
189
190
}
190
191
192
+ /// SAFETY: we call `set_table` for each member that implements `Fetch`
191
193
#[ inline]
192
194
unsafe fn set_table( & mut self , _state: & Self :: State , _table: & #path:: storage:: Table ) {
193
195
#( self . #field_idents. set_table( & _state. #field_idents, _table) ; ) *
194
196
}
195
197
198
+ /// SAFETY: we call `table_fetch` for each member that implements `Fetch` or
199
+ /// `table_filter_fetch` if it also implements `FilterFetch`.
196
200
#[ inline]
197
201
unsafe fn table_fetch( & mut self , _table_row: usize ) -> Self :: Item {
198
202
use #path:: query:: FilterFetch ;
@@ -203,6 +207,8 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
203
207
}
204
208
}
205
209
210
+ /// SAFETY: we call `archetype_fetch` for each member that implements `Fetch` or
211
+ /// `archetype_filter_fetch` if it also implements `FilterFetch`.
206
212
#[ inline]
207
213
unsafe fn archetype_fetch( & mut self , _archetype_index: usize ) -> Self :: Item {
208
214
use #path:: query:: FilterFetch ;
@@ -214,7 +220,7 @@ pub fn derive_fetch_impl(input: TokenStream) -> TokenStream {
214
220
}
215
221
}
216
222
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
218
224
unsafe impl #impl_generics #path:: query:: FetchState for #state_struct_name #ty_generics #where_clause {
219
225
fn init( world: & mut #path:: world:: World ) -> Self {
220
226
#state_struct_name {
@@ -260,9 +266,9 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
260
266
impl_generics,
261
267
ty_generics,
262
268
where_clause,
263
- struct_has_world_lt ,
264
- world_lt ,
265
- state_lt ,
269
+ struct_has_world_lifetime ,
270
+ world_lifetime ,
271
+ state_lifetime ,
266
272
} = fetch_impl_tokens ( & ast) ;
267
273
268
274
// 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 {
271
277
// - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=da5e260a5c2f3e774142d60a199e854a (this fails)
272
278
// - https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=802517bb3d8f83c45ee8c0be360bb250 (this compiles)
273
279
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 ) ;
277
283
}
278
284
fetch_generics
279
285
. params
@@ -283,7 +289,7 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
283
289
) ) ) ) ;
284
290
let ( fetch_impl_generics, _, _) = fetch_generics. split_for_impl ( ) ;
285
291
let mut fetch_generics = ast. generics . clone ( ) ;
286
- if struct_has_world_lt {
292
+ if struct_has_world_lifetime {
287
293
* fetch_generics. params . first_mut ( ) . unwrap ( ) =
288
294
GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'fetch" , Span :: call_site ( ) ) ) ) ;
289
295
}
@@ -410,6 +416,7 @@ pub fn derive_filter_fetch_impl(input: TokenStream) -> TokenStream {
410
416
tokens
411
417
}
412
418
419
+ // This struct is used to share common tokens between `Fetch` and `FilterFetch` implementations.
413
420
struct FetchImplTokens < ' a > {
414
421
struct_name : Ident ,
415
422
fetch_struct_name : Ident ,
@@ -418,26 +425,26 @@ struct FetchImplTokens<'a> {
418
425
impl_generics : ImplGenerics < ' a > ,
419
426
ty_generics : TypeGenerics < ' a > ,
420
427
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 ,
424
431
}
425
432
426
433
fn 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 {
428
435
lt @ GenericParam :: Lifetime ( _) => Some ( lt. clone ( ) ) ,
429
436
_ => None ,
430
437
} ) ;
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 ( || {
433
440
GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'world" , Span :: call_site ( ) ) ) )
434
441
} ) ;
435
- let state_lt =
442
+ let state_lifetime =
436
443
GenericParam :: Lifetime ( LifetimeDef :: new ( Lifetime :: new ( "'state" , Span :: call_site ( ) ) ) ) ;
437
444
438
445
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 ( ) ) ;
441
448
442
449
let ( impl_generics, ty_generics, where_clause) = ast. generics . split_for_impl ( ) ;
443
450
@@ -453,9 +460,9 @@ fn fetch_impl_tokens(ast: &DeriveInput) -> FetchImplTokens {
453
460
impl_generics,
454
461
ty_generics,
455
462
where_clause,
456
- struct_has_world_lt ,
457
- world_lt ,
458
- state_lt ,
463
+ struct_has_world_lifetime ,
464
+ world_lifetime ,
465
+ state_lifetime ,
459
466
}
460
467
}
461
468
0 commit comments