@@ -274,16 +274,16 @@ use std::{any::TypeId, borrow::Borrow, fmt::Debug};
274
274
/// [`With`]: crate::query::With
275
275
/// [`Without`]: crate::query::Without
276
276
pub struct Query < ' world , ' state , Q : WorldQuery , F : ReadOnlyWorldQuery = ( ) > {
277
- pub ( crate ) world : & ' world World ,
278
- pub ( crate ) state : & ' state QueryState < Q , F > ,
279
- pub ( crate ) last_change_tick : u32 ,
280
- pub ( crate ) change_tick : u32 ,
277
+ world : & ' world World ,
278
+ state : & ' state QueryState < Q , F > ,
279
+ last_change_tick : u32 ,
280
+ change_tick : u32 ,
281
281
// SAFETY: This is used to ensure that `get_component_mut::<C>` properly fails when a Query writes C
282
282
// and gets converted to a read-only query using `to_readonly`. Without checking this, `get_component_mut` relies on
283
283
// QueryState's archetype_component_access, which will continue allowing write access to C after being cast to
284
284
// the read-only variant. This whole situation is confusing and error prone. Ideally this is a temporary hack
285
285
// until we sort out a cleaner alternative.
286
- pub ( crate ) force_read_only_component_access : bool ,
286
+ force_read_only_component_access : bool ,
287
287
}
288
288
289
289
impl < ' w , ' s , Q : WorldQuery , F : ReadOnlyWorldQuery > std:: fmt:: Debug for Query < ' w , ' s , Q , F > {
@@ -309,11 +309,12 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
309
309
state : & ' s QueryState < Q , F > ,
310
310
last_change_tick : u32 ,
311
311
change_tick : u32 ,
312
+ force_read_only_component_access : bool ,
312
313
) -> Self {
313
314
state. validate_world ( world) ;
314
315
315
316
Self {
316
- force_read_only_component_access : false ,
317
+ force_read_only_component_access,
317
318
world,
318
319
state,
319
320
last_change_tick,
@@ -329,14 +330,16 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
329
330
pub fn to_readonly ( & self ) -> Query < ' _ , ' s , Q :: ReadOnly , F :: ReadOnly > {
330
331
let new_state = self . state . as_readonly ( ) ;
331
332
// SAFETY: This is memory safe because it turns the query immutable.
332
- Query {
333
- // SAFETY: this must be set to true or `get_component_mut` will be unsound. See the comments
334
- // on this field for more details
335
- force_read_only_component_access : true ,
336
- world : self . world ,
337
- state : new_state,
338
- last_change_tick : self . last_change_tick ,
339
- change_tick : self . change_tick ,
333
+ unsafe {
334
+ Query :: new (
335
+ self . world ,
336
+ new_state,
337
+ self . last_change_tick ,
338
+ self . change_tick ,
339
+ // SAFETY: this must be set to true or `get_component_mut` will be unsound. See the comments
340
+ // on this field for more details
341
+ true ,
342
+ )
340
343
}
341
344
}
342
345
0 commit comments