From 4d6c553b1b668693f5995a8e2b44e0ba45112a09 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Thu, 11 Jun 2020 19:44:03 +0100 Subject: [PATCH] Fixed suppressed clippy warnings for #587 - redundant_closure --- common/src/comp/inventory/slot.rs | 5 +- server/src/persistence/character.rs | 8 +-- server/src/sys/entity_sync.rs | 3 +- .../src/audio/sfx/event_mapper/combat/mod.rs | 6 +- .../audio/sfx/event_mapper/movement/mod.rs | 6 +- voxygen/src/menu/main/ui.rs | 4 +- voxygen/src/mesh/terrain.rs | 4 +- voxygen/src/render/consts.rs | 4 +- voxygen/src/render/instances.rs | 6 +- voxygen/src/render/model.rs | 6 +- voxygen/src/render/texture.rs | 7 +-- voxygen/src/scene/terrain.rs | 4 +- voxygen/src/settings.rs | 4 +- voxygen/src/ui/event.rs | 3 +- world/src/sim/mod.rs | 58 +++++++++---------- 15 files changed, 55 insertions(+), 73 deletions(-) diff --git a/common/src/comp/inventory/slot.rs b/common/src/comp/inventory/slot.rs index b6e94543e0..a15b842820 100644 --- a/common/src/comp/inventory/slot.rs +++ b/common/src/comp/inventory/slot.rs @@ -139,7 +139,6 @@ pub fn loadout_remove(equip_slot: EquipSlot, loadout: &mut Loadout) -> Option, Error>; /// /// After first logging in, and after a character is selected, we fetch this /// data for the purpose of inserting their persisted data for the entity. -#[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + pub fn load_character_data( character_id: i32, db_dir: &str, @@ -63,7 +63,7 @@ pub fn load_character_data( comp::Inventory::default() }, - |inv| comp::Inventory::from(inv), + comp::Inventory::from, ), maybe_loadout.map_or_else( || { @@ -102,7 +102,7 @@ pub fn load_character_data( /// In the event that a join fails, for a character (i.e. they lack an entry for /// stats, body, etc...) the character is skipped, and no entry will be /// returned. -#[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + pub fn load_character_list(player_uuid: &str, db_dir: &str) -> CharacterListResult { let data = schema::character::dsl::character .filter(schema::character::player_uuid.eq(player_uuid)) @@ -127,7 +127,7 @@ pub fn load_character_list(player_uuid: &str, db_dir: &str) -> CharacterListResu )) .build() }, - |data| comp::Loadout::from(data), + comp::Loadout::from, ); CharacterItem { diff --git a/server/src/sys/entity_sync.rs b/server/src/sys/entity_sync.rs index 8bb433b3a2..041c88cfde 100644 --- a/server/src/sys/entity_sync.rs +++ b/server/src/sys/entity_sync.rs @@ -44,7 +44,6 @@ impl<'a> System<'a> for Sys { ReadTrackers<'a>, ); - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 fn run( &mut self, ( @@ -163,7 +162,7 @@ impl<'a> System<'a> for Sys { region.entities(), deleted_entities .take_deleted_in_region(key) - .unwrap_or_else(|| Vec::new()), + .unwrap_or_default(), ); let entity_sync_msg = ServerMsg::EntitySync(entity_sync_package); let comp_sync_msg = ServerMsg::CompSync(comp_sync_package); diff --git a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs index a025ebd001..6bc95d09e1 100644 --- a/voxygen/src/audio/sfx/event_mapper/combat/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/combat/mod.rs @@ -39,7 +39,6 @@ pub struct CombatEventMapper { } impl EventMapper for CombatEventMapper { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 fn maintain(&mut self, state: &State, player_entity: EcsEntity, triggers: &SfxTriggers) { let ecs = state.ecs(); @@ -63,10 +62,7 @@ impl EventMapper for CombatEventMapper { }) { if let Some(character) = character { - let state = self - .event_history - .entry(entity) - .or_insert_with(|| PreviousEntityState::default()); + let state = self.event_history.entry(entity).or_default(); let mapped_event = Self::map_event(character, state, loadout); diff --git a/voxygen/src/audio/sfx/event_mapper/movement/mod.rs b/voxygen/src/audio/sfx/event_mapper/movement/mod.rs index 955aa56d94..88d183a349 100644 --- a/voxygen/src/audio/sfx/event_mapper/movement/mod.rs +++ b/voxygen/src/audio/sfx/event_mapper/movement/mod.rs @@ -36,7 +36,6 @@ pub struct MovementEventMapper { } impl EventMapper for MovementEventMapper { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 fn maintain(&mut self, state: &State, player_entity: EcsEntity, triggers: &SfxTriggers) { let ecs = state.ecs(); @@ -62,10 +61,7 @@ impl EventMapper for MovementEventMapper { }) { if let Some(character) = character { - let state = self - .event_history - .entry(entity) - .or_insert_with(|| PreviousEntityState::default()); + let state = self.event_history.entry(entity).or_default(); let mapped_event = match body { Body::Humanoid(_) => Self::map_movement_event(character, physics, state, vel.0), diff --git a/voxygen/src/menu/main/ui.rs b/voxygen/src/menu/main/ui.rs index a9e66c4ec0..7b16bb1553 100644 --- a/voxygen/src/menu/main/ui.rs +++ b/voxygen/src/menu/main/ui.rs @@ -162,7 +162,6 @@ pub struct MainMenuUi { } impl MainMenuUi { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn new(global_state: &mut GlobalState) -> Self { let window = &mut global_state.window; let networking = &global_state.settings.networking; @@ -216,7 +215,8 @@ impl MainMenuUi { server_address: networking .servers .get(networking.default_server) - .map_or_else(|| String::new(), |address| address.clone()), + .cloned() + .unwrap_or_default(), popup: None, connecting: None, show_servers: false, diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index e6ba3de44d..ad393baf47 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -211,7 +211,7 @@ impl<'a, V: RectRasterableVol + ReadVol + Debug> #[allow(clippy::needless_range_loop)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::panic_params)] // TODO: Pending review in #587 - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + fn generate_mesh( &'a self, range: Self::Supplement, @@ -343,7 +343,7 @@ impl<'a, V: RectRasterableVol + ReadVol + Debug> maybe_block .filter(|vox| vox.is_opaque() && (!neighbour || vox.is_blended())) .and_then(|vox| vox.get_color()) - .map(|col| Rgba::from_opaque(col)) + .map(Rgba::from_opaque) .unwrap_or(Rgba::zero()) }; diff --git a/voxygen/src/render/consts.rs b/voxygen/src/render/consts.rs index 8f6f7b7ec7..effe76e8c0 100644 --- a/voxygen/src/render/consts.rs +++ b/voxygen/src/render/consts.rs @@ -18,7 +18,7 @@ impl Consts { } /// Update the GPU-side value represented by this constant handle. - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + pub fn update( &mut self, encoder: &mut gfx::Encoder, @@ -26,6 +26,6 @@ impl Consts { ) -> Result<(), RenderError> { encoder .update_buffer(&self.buf, vals, 0) - .map_err(|err| RenderError::UpdateError(err)) + .map_err(RenderError::UpdateError) } } diff --git a/voxygen/src/render/instances.rs b/voxygen/src/render/instances.rs index 1feaafb5ed..c99be74ffa 100644 --- a/voxygen/src/render/instances.rs +++ b/voxygen/src/render/instances.rs @@ -12,18 +12,16 @@ pub struct Instances { } impl Instances { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Result { Ok(Self { ibuf: factory .create_buffer(len, Role::Vertex, Usage::Dynamic, Bind::TRANSFER_DST) - .map_err(|err| RenderError::BufferCreationError(err))?, + .map_err(RenderError::BufferCreationError)?, }) } pub fn count(&self) -> usize { self.ibuf.len() } - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn update( &mut self, encoder: &mut gfx::Encoder, @@ -31,6 +29,6 @@ impl Instances { ) -> Result<(), RenderError> { encoder .update_buffer(&self.ibuf, instances, 0) - .map_err(|err| RenderError::UpdateError(err)) + .map_err(RenderError::UpdateError) } } diff --git a/voxygen/src/render/model.rs b/voxygen/src/render/model.rs index 20ef6c7c52..d994215d1d 100644 --- a/voxygen/src/render/model.rs +++ b/voxygen/src/render/model.rs @@ -30,12 +30,11 @@ pub struct DynamicModel { } impl DynamicModel

{ - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn new(factory: &mut gfx_backend::Factory, size: usize) -> Result { Ok(Self { vbuf: factory .create_buffer(size, Role::Vertex, Usage::Dynamic, Bind::empty()) - .map_err(|err| RenderError::BufferCreationError(err))?, + .map_err(RenderError::BufferCreationError)?, }) } @@ -48,7 +47,6 @@ impl DynamicModel

{ } } - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn update( &self, encoder: &mut gfx::Encoder, @@ -57,6 +55,6 @@ impl DynamicModel

{ ) -> Result<(), RenderError> { encoder .update_buffer(&self.vbuf, mesh.vertices(), offset) - .map_err(|err| RenderError::UpdateError(err)) + .map_err(RenderError::UpdateError) } } diff --git a/voxygen/src/render/texture.rs b/voxygen/src/render/texture.rs index 30a55a273d..f166b9d2c4 100644 --- a/voxygen/src/render/texture.rs +++ b/voxygen/src/render/texture.rs @@ -26,7 +26,6 @@ where F::Channel: gfx::format::TextureChannel, ::DataType: Copy, { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn new( factory: &mut gfx_backend::Factory, image: &DynamicImage, @@ -43,7 +42,7 @@ where gfx::texture::Mipmap::Provided, &[&image.raw_pixels()], ) - .map_err(|err| RenderError::CombinedError(err))?; + .map_err(RenderError::CombinedError)?; Ok(Self { tex, @@ -89,7 +88,7 @@ where /// Update a texture with the given data (used for updating the glyph cache /// texture). - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + pub fn update( &self, encoder: &mut gfx::Encoder, @@ -111,7 +110,7 @@ where .update_texture::<::Surface, F>( &self.tex, None, info, data, ) - .map_err(|err| RenderError::TexUpdateError(err)) + .map_err(RenderError::TexUpdateError) } /// Get dimensions of the represented image. diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index e84f36d502..1b645d2b9a 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -248,7 +248,7 @@ fn sprite_config_for(kind: BlockKind) -> Option { /// Function executed by worker threads dedicated to chunk meshing. #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 -#[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + fn mesh_worker + RectRasterableVol + ReadVol + Debug>( pos: Vec2, z_bounds: (f32, f32), @@ -292,7 +292,7 @@ fn mesh_worker + RectRasterableVol + ReadVol + Debug>( instances .entry((block.kind(), seed as usize % cfg.variations)) - .or_insert_with(|| Vec::new()) + .or_insert_with(Vec::new) .push(instance); } } diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index ca44109e12..290e97bcd4 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -676,7 +676,7 @@ pub struct Settings { impl Default for Settings { #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + fn default() -> Self { let user_dirs = UserDirs::new().expect("System's $HOME directory path not found!"); @@ -690,7 +690,7 @@ impl Default for Settings { .or(user_dirs.picture_dir().map(|dir| dir.join("veloren"))) .or(std::env::current_exe() .ok() - .and_then(|dir| dir.parent().map(|val| PathBuf::from(val)))) + .and_then(|dir| dir.parent().map(PathBuf::from))) .expect("Couldn't choose a place to store the screenshots"); Settings { diff --git a/voxygen/src/ui/event.rs b/voxygen/src/ui/event.rs index c9a3dde678..b6a6dc20d7 100644 --- a/voxygen/src/ui/event.rs +++ b/voxygen/src/ui/event.rs @@ -4,7 +4,6 @@ use vek::*; #[derive(Clone)] pub struct Event(pub Input); impl Event { - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn try_from( event: glutin::Event, window: &glutin::ContextWrapper, @@ -23,7 +22,7 @@ impl Event { fn hidpi_factor(&self) -> f32 { winit::Window::get_hidpi_factor(&self.0) as _ } } - convert_event!(event, &WindowRef(window.window())).map(|input| Self(input)) + convert_event!(event, &WindowRef(window.window())).map(Self) } pub fn is_keyboard_or_mouse(&self) -> bool { diff --git a/world/src/sim/mod.rs b/world/src/sim/mod.rs index 1481717462..d8878fd111 100644 --- a/world/src/sim/mod.rs +++ b/world/src/sim/mod.rs @@ -305,7 +305,7 @@ pub struct WorldSim { impl WorldSim { #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 #[allow(clippy::let_and_return)] // TODO: Pending review in #587 - #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 + pub fn generate(seed: u32, opts: WorldOpts) -> Self { let mut rng = ChaChaRng::from_seed(seed_expan::rng_state(seed)); // NOTE: Change 1.0 to 4.0, while multiplying grid_size by 4, for a 4x @@ -976,22 +976,22 @@ impl WorldSim { // varying conditions &rock_strength_nz, // initial conditions - |posi| alt_func(posi), + alt_func, |posi| alt_func(posi) - if is_ocean_fn(posi) { 0.0 } else { 0.0 }, is_ocean_fn, // empirical constants uplift_fn, - |posi| n_func(posi), - |posi| theta_func(posi), - |posi| kf_func(posi), - |posi| kd_func(posi), - |posi| g_func(posi), - |posi| epsilon_0_func(posi), - |posi| alpha_func(posi), + n_func, + theta_func, + kf_func, + kd_func, + g_func, + epsilon_0_func, + alpha_func, // scaling factors - |n| height_scale(n), + height_scale, k_d_scale(n_approx), - |q| k_da_scale(q), + k_da_scale, ); // Quick "small scale" erosion cycle in order to lower extreme angles. @@ -1004,16 +1004,16 @@ impl WorldSim { |posi| basement[posi] as f32, is_ocean_fn, |posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t), - |posi| n_func(posi), - |posi| theta_func(posi), - |posi| kf_func(posi), - |posi| kd_func(posi), - |posi| g_func(posi), - |posi| epsilon_0_func(posi), - |posi| alpha_func(posi), - |n| height_scale(n), + n_func, + theta_func, + kf_func, + kd_func, + g_func, + epsilon_0_func, + alpha_func, + height_scale, k_d_scale(n_approx), - |q| k_da_scale(q), + k_da_scale, ) }; @@ -1071,16 +1071,16 @@ impl WorldSim { |posi| basement[posi] as f32, is_ocean_fn, |posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t), - |posi| n_func(posi), - |posi| theta_func(posi), - |posi| kf_func(posi), - |posi| kd_func(posi), - |posi| g_func(posi), - |posi| epsilon_0_func(posi), - |posi| alpha_func(posi), - |n| height_scale(n), + n_func, + theta_func, + kf_func, + kd_func, + g_func, + epsilon_0_func, + alpha_func, + height_scale, k_d_scale(n_approx), - |q| k_da_scale(q), + k_da_scale, ) };