Skip to content

Commit

Permalink
Fix errors and warnings in tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Imberflur committed Jul 23, 2023
1 parent 0fad41d commit 2c7d5e6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
4 changes: 4 additions & 0 deletions benches/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl Component for Lifetime {
}

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
struct Ball {
radius: f32,
}
Expand All @@ -64,6 +65,7 @@ impl Component for Ball {
}

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
struct Rect {
a: f32,
b: f32,
Expand Down Expand Up @@ -91,6 +93,7 @@ impl Component for SpawnRequests {
}

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
struct Collision {
a: Entity,
b: Entity,
Expand All @@ -102,6 +105,7 @@ impl Component for Collision {
}

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
struct Room {
inner_width: f32,
inner_height: f32,
Expand Down
2 changes: 1 addition & 1 deletion examples/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'a> System<'a> for SysB {
fn run(&mut self, (entities, mut tracked): Self::SystemData) {
for (entity, mut restricted) in (&entities, &mut tracked.restrict_mut()).join() {
if entity.id() % 2 == 0 {
let mut comp = restricted.get_mut_unchecked();
let mut comp = restricted.get_mut();
comp.0 += 1;
}
}
Expand Down
28 changes: 15 additions & 13 deletions src/storage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ mod test {
for i in 0..1_000 {
*s.get_mut(Entity::new(i, Generation::new(1)))
.unwrap()
.access_mut()
.as_mut() -= 718;
}

Expand Down Expand Up @@ -330,6 +331,7 @@ mod test {
for i in 0..1_000 {
*s.get_mut_or_default(Entity::new(i, Generation::new(1)))
.unwrap()
.access_mut()
.as_mut() += i;
}

Expand Down Expand Up @@ -698,9 +700,9 @@ mod test {
}

for mut comps in (&mut s1.restrict_mut()).join() {
let c1 = { comps.get_unchecked().0 };
let c1 = { comps.get().0 };

let c2 = { comps.get_mut_unchecked().0 };
let c2 = { comps.get_mut().0 };

assert_eq!(
c1, c2,
Expand Down Expand Up @@ -740,14 +742,12 @@ mod test {
let components2 = Mutex::new(Vec::new());
let components2_mut = Mutex::new(Vec::new());

(&mut s1.par_restrict_mut())
.par_join()
.for_each(|mut comps| {
let (mut components2, mut components2_mut) =
(components2.lock().unwrap(), components2_mut.lock().unwrap());
components2.push(comps.get_unchecked().0);
components2_mut.push(comps.get_mut_unchecked().0);
});
(&mut s1.restrict_mut()).par_join().for_each(|mut comps| {
let (mut components2, mut components2_mut) =
(components2.lock().unwrap(), components2_mut.lock().unwrap());
components2.push(comps.get().0);
components2_mut.push(comps.get_mut().0);
});
let components2 = components2.into_inner().unwrap();
assert_eq!(
components2,
Expand Down Expand Up @@ -994,7 +994,7 @@ mod test {

#[test]
fn entries() {
use crate::{join::Join, storage::WriteStorage, world::Entities};
use crate::{join::LendJoin, storage::WriteStorage, world::Entities};

let mut w = World::new();

Expand All @@ -1018,10 +1018,12 @@ mod test {
let mut sum = 0;

w.exec(|(e, mut s): (Entities, WriteStorage<CEntries>)| {
sum = (&e, s.entries()).join().fold(0, |acc, (_, value)| {
let mut acc = 0;
(&e, s.entries()).lend_join().for_each(|(_, value)| {
let v = value.or_insert(2.into());
acc + v.0
acc = acc + v.0;
});
sum = acc;
});

assert_eq!(sum, 135);
Expand Down
2 changes: 2 additions & 0 deletions tests/saveload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod tests {
struct TupleSerdeType(u32);

#[derive(Clone)]
#[allow(dead_code)]
struct UnserializableType {
inner: u32,
}
Expand All @@ -67,6 +68,7 @@ mod tests {
}

#[derive(Serialize, Deserialize, Clone)]
#[allow(dead_code)]
struct ComplexSerdeType {
#[serde(skip, default)]
opaque: UnserializableType,
Expand Down
14 changes: 10 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ fn par_join_many_entities_and_systems() {
}

#[test]
fn getting_specific_entity_with_join() {
fn getting_specific_entity_with_lend_join() {
let mut world = create_world();
world
.create_entity()
Expand All @@ -565,12 +565,16 @@ fn getting_specific_entity_with_join() {

assert_eq!(
Some((&CompInt(1), &mut CompBool(true))),
(&ints, &mut bools).join().get(entity, &world.entities())
(&ints, &mut bools)
.lend_join()
.get(entity, &world.entities())
);
bools.remove(entity);
assert_eq!(
None,
(&ints, &mut bools).join().get(entity, &world.entities())
(&ints, &mut bools)
.lend_join()
.get(entity, &world.entities())
);
entity
};
Expand All @@ -584,7 +588,9 @@ fn getting_specific_entity_with_join() {
let mut bools = world.write_storage::<CompBool>();
assert_eq!(
None,
(&ints, &mut bools).join().get(entity, &world.entities())
(&ints, &mut bools)
.lend_join()
.get(entity, &world.entities())
);
}

Expand Down

0 comments on commit 2c7d5e6

Please sign in to comment.