Skip to content

Commit

Permalink
Merge pull request amethyst#2710 from cowboy-bebug/fix/clippy-warnings
Browse files Browse the repository at this point in the history
Fix clippy warnings and errors
  • Loading branch information
dawnlarsson authored Aug 25, 2021
2 parents de9bad7 + 8e66499 commit 6bf270f
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 108 deletions.
2 changes: 1 addition & 1 deletion amethyst_animation/src/systems/sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn sampler_interpolation<T: AnimationSampling + std::fmt::Debug>(
}

Some(BlendMethod::Linear) => {
if let Some(p) = linear_blend::<T>(channel, &inner) {
if let Some(p) = linear_blend::<T>(channel, inner) {
comp.apply_sample(channel, &p, commands);
}
}
Expand Down
4 changes: 2 additions & 2 deletions amethyst_assets/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ where
fn import_simple(&self, bytes: Vec<u8>) -> Result<D, Error> {
use serde_json::de::Deserializer;
let mut d = Deserializer::from_slice(&bytes);
let val = D::deserialize(&mut d)
.with_context(|_| format_err!("Failed deserializing Json file"))?;
d.end()
.with_context(|_| format_err!("Failed deserializing Json file"))?;

let val = D::deserialize(&mut d)
.with_context(|_| format_err!("Failed deserializing Json file"))?;
Ok(val)
}
}
2 changes: 1 addition & 1 deletion amethyst_assets/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl DefaultLoader {
log::info!("Using RpcIO");
let rpc_io = connect_string
.and_then(|cs| RpcIO::new(cs).ok())
.unwrap_or_else(RpcIO::default);
.unwrap_or_default();
Box::new(rpc_io)
} else {
log::info!("Using PackfileIO");
Expand Down
29 changes: 16 additions & 13 deletions amethyst_audio/src/systems/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ impl System for AudioSystem {
#[cfg(feature = "profiler")]
profile_scope!("audio_system");
// Process emitters and listener.
if let Some((entity, listener)) = if let Some(entity) = select_listener.0 {
if let Some((entity, listener)) = select_listener.0.map_or_else(
// Select the first available AudioListener by default
|| {
q_audio_listener
.iter(world)
.next()
.map(|(entity, audio_listener)| (*entity, audio_listener))
},
// Find entity referred by SelectedListener resource
world
.entry_ref(entity)
.ok()
.and_then(|entry| entry.into_component::<AudioListener>().ok())
.map(|audio_listener| (entity, audio_listener))
} else {
// Otherwise, select the first available AudioListener
q_audio_listener
.iter(world)
.next()
.map(|(entity, audio_listener)| (*entity, audio_listener))
} {
|entity| {
world
.entry_ref(entity)
.ok()
.and_then(|entry| entry.into_component::<AudioListener>().ok())
.map(|audio_listener| (entity, audio_listener))
},
) {
if let Some(listener_transform) = world
.entry_ref(entity)
.ok()
Expand Down
5 changes: 2 additions & 3 deletions amethyst_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ impl Error for ConfigError {
fn description(&self) -> &str {
match *self {
ConfigError::File(_) => "Project file error",
ConfigError::Parser(_) => "Project parser error",
ConfigError::FileParser(_, _) => "Project parser error",
ConfigError::FileParser(_, _) | ConfigError::Parser(_) => "Project parser error",
ConfigError::Serializer(_) => "Project serializer error",
ConfigError::Extension(_) => "Invalid extension or directory for a file",
#[cfg(feature = "json")]
Expand Down Expand Up @@ -222,8 +221,8 @@ where
ConfigFormat::Ron => {
ron::de::Deserializer::from_bytes(bytes)
.and_then(|mut de| {
let val = T::deserialize(&mut de)?;
de.end()?;
let val = T::deserialize(&mut de)?;
Ok(val)
})
.map_err(ConfigError::Parser)
Expand Down
34 changes: 19 additions & 15 deletions amethyst_controls/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,18 @@ impl System for FreeRotationSystem {
let focused = focus.is_focused;
for event in events.read(&mut self.reader) {
if focused && hide.hide {
if let Event::DeviceEvent { ref event, .. } = *event {
if let DeviceEvent::MouseMotion { delta: (x, y) } = *event {
for transform in controls.iter_mut(world) {
transform.append_rotation_x_axis(
(-(y as f32) * self.sensitivity_y).to_radians(),
);
transform.prepend_rotation_y_axis(
(-(x as f32) * self.sensitivity_x).to_radians(),
);
}
if let Event::DeviceEvent {
event: DeviceEvent::MouseMotion { delta: (x, y) },
..
} = *event
{
for transform in controls.iter_mut(world) {
transform.append_rotation_x_axis(
(-(y as f32) * self.sensitivity_y).to_radians(),
);
transform.prepend_rotation_y_axis(
(-(x as f32) * self.sensitivity_x).to_radians(),
);
}
}
}
Expand Down Expand Up @@ -171,11 +173,13 @@ impl System for MouseFocusUpdateSystem {
profile_scope!("mouse_focus_update_system");

for event in events.read(&mut self.reader) {
if let Event::WindowEvent { ref event, .. } = *event {
if let WindowEvent::Focused(focused) = *event {
log::debug!("Window was focused.");
focus.is_focused = focused;
}
if let Event::WindowEvent {
event: WindowEvent::Focused(focused),
..
} = *event
{
log::debug!("Window was focused.");
focus.is_focused = focused;
}
}
}),
Expand Down
2 changes: 1 addition & 1 deletion amethyst_core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ pub mod tests {

dispatcher.execute(&mut world, &mut resources);

assert_eq!(resources.get::<MyResource>().unwrap().0, true);
assert!(resources.get::<MyResource>().unwrap().0, true);
}
}
47 changes: 25 additions & 22 deletions amethyst_core/src/hide_hierarchy_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ impl System for HideHierarchySystem {
#[cfg(test)]
mod test {
use super::*;
use crate::transform::{MissingPreviousParentSystem, Parent, ParentUpdateSystem, Transform};
use crate::{
ecs::*,
transform::{MissingPreviousParentSystem, Parent, ParentUpdateSystem, Transform},
};

#[test]
fn should_not_add_hidden_to_child_if_not_propagated() {
Expand Down Expand Up @@ -98,7 +101,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -107,7 +110,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -116,7 +119,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e2)
Expand All @@ -132,7 +135,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -143,7 +146,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -152,7 +155,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e2)
Expand Down Expand Up @@ -190,7 +193,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -199,7 +202,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -214,7 +217,7 @@ mod test {
.add_component(HiddenPropagate::new());
schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -223,7 +226,7 @@ mod test {
.is_ok()
);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -238,7 +241,7 @@ mod test {
.remove_component::<HiddenPropagate>();
schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -247,7 +250,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand Down Expand Up @@ -283,7 +286,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -292,7 +295,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -301,7 +304,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e2)
Expand All @@ -316,7 +319,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -327,7 +330,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -336,7 +339,7 @@ mod test {
.is_ok()
);

assert_eq!(
assert!(
true,
world
.entry(e2)
Expand All @@ -350,7 +353,7 @@ mod test {
.unwrap()
.remove_component::<HiddenPropagate>();

assert_eq!(
assert!(
true,
world
.entry(parent)
Expand All @@ -361,7 +364,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
true,
world
.entry(e1)
Expand All @@ -370,7 +373,7 @@ mod test {
.is_err()
);

assert_eq!(
assert!(
true,
world
.entry(e2)
Expand Down
4 changes: 2 additions & 2 deletions amethyst_core/src/system_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod test {
fn should_not_pause_if_resource_match_value() {
let mut resources = Resources::default();
let mut world = World::default();
resources.insert(0u32);
resources.insert(0_u32);
resources.insert(CurrentState::Enabled);

let mut dispatcher = DispatcherBuilder::default()
Expand All @@ -200,7 +200,7 @@ mod test {
fn should_pause_if_resource_does_not_match_value() {
let mut resources = Resources::default();
let mut world = World::default();
resources.insert(0u32);
resources.insert(0_u32);
resources.insert(CurrentState::Enabled);

let mut dispatcher = DispatcherBuilder::default()
Expand Down
5 changes: 3 additions & 2 deletions amethyst_core/src/transform/missing_previous_parent_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl System for MissingPreviousParentSystem {
#[cfg(test)]
mod test {
use super::*;
use crate::ecs::*;

#[test]
fn previous_parent_added() {
Expand All @@ -49,7 +50,7 @@ mod test {

schedule.execute(&mut world, &mut resources);

assert_eq!(
assert!(
world
.entry(e1)
.unwrap()
Expand All @@ -58,7 +59,7 @@ mod test {
false
);

assert_eq!(
assert!(
world
.entry(e2)
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion amethyst_core/src/transform/parent_update_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl System for ParentUpdateSystem {
#[cfg(test)]
mod test {
use super::*;
use crate::transform::MissingPreviousParentSystem;
use crate::{ecs::*, transform::MissingPreviousParentSystem};

#[test]
fn correct_children() {
Expand Down
Loading

0 comments on commit 6bf270f

Please sign in to comment.