Skip to content

Commit

Permalink
:(
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Sep 2, 2022
1 parent 17d84e8 commit dd80e6a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 142 deletions.
124 changes: 0 additions & 124 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,130 +956,6 @@ mod tests {
);
}
}

#[test]
fn convert_mut_to_immut() {
{
let mut world = World::new();

fn mutable_query(mut query: Query<&mut A>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<&A>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<Option<&mut A>>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<Option<&A>>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &B)>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B)>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &mut B)>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B)>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &mut B), With<C>>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B), With<C>>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &mut B), Without<C>>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B), Without<C>>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &mut B), Added<C>>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B), Added<C>>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}

{
let mut world = World::new();

fn mutable_query(mut query: Query<(&mut A, &mut B), Changed<C>>) {
for _ in &mut query {}

immutable_query(query.to_readonly());
}

fn immutable_query(_: Query<(&A, &B), Changed<C>>) {}

let mut sys = IntoSystem::into_system(mutable_query);
sys.initialize(&mut world);
}
}

#[test]
fn update_archetype_component_access_works() {
use std::collections::HashSet;
Expand Down
18 changes: 0 additions & 18 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,24 +302,6 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
}
}

/// Downgrades all data accessed in this query to a read-only form.
///
/// For example, `Query<(&mut A, &B, &mut C), With<D>>` will become `Query<(&A, &B, &C), With<D>>`.
/// This can be useful when working around the borrow checker,
/// or reusing functionality between systems via functions that accept query types.
pub fn to_readonly(&self) -> Query<'_, 's, Q::ReadOnly, F::ReadOnly> {
let new_state = self.state.as_readonly();
// SAFETY: This is memory safe because it turns the query immutable.
unsafe {
Query::new(
self.world,
new_state,
self.last_change_tick,
self.change_tick,
)
}
}

/// Returns an [`Iterator`] over the query results.
///
/// This can only return immutable data (mutable data will be cast to an immutable form).
Expand Down

0 comments on commit dd80e6a

Please sign in to comment.