Fixed suppressed clippy warnings for #587 - redundant_closure

This commit is contained in:
Ben Wallis 2020-06-11 19:44:03 +01:00
parent 7459a1e95a
commit 4d6c553b1b
15 changed files with 55 additions and 73 deletions

View File

@ -139,7 +139,6 @@ pub fn loadout_remove(equip_slot: EquipSlot, loadout: &mut Loadout) -> Option<it
loadout_replace(equip_slot, None, loadout) loadout_replace(equip_slot, None, loadout)
} }
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
fn swap_inventory_loadout( fn swap_inventory_loadout(
inventory_slot: usize, inventory_slot: usize,
equip_slot: EquipSlot, equip_slot: EquipSlot,
@ -157,9 +156,7 @@ fn swap_inventory_loadout(
let from_inv = if let Some(item) = from_equip { let from_inv = if let Some(item) = from_equip {
// If this fails and we get item back as an err it will just be put back in the // If this fails and we get item back as an err it will just be put back in the
// loadout // loadout
inventory inventory.insert(inventory_slot, item).unwrap_or_else(Some)
.insert(inventory_slot, item)
.unwrap_or_else(|i| Some(i))
} else { } else {
inventory.remove(inventory_slot) inventory.remove(inventory_slot)
}; };

View File

@ -23,7 +23,7 @@ type CharacterListResult = Result<Vec<CharacterItem>, Error>;
/// ///
/// After first logging in, and after a character is selected, we fetch this /// 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. /// 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( pub fn load_character_data(
character_id: i32, character_id: i32,
db_dir: &str, db_dir: &str,
@ -63,7 +63,7 @@ pub fn load_character_data(
comp::Inventory::default() comp::Inventory::default()
}, },
|inv| comp::Inventory::from(inv), comp::Inventory::from,
), ),
maybe_loadout.map_or_else( 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 /// 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 /// stats, body, etc...) the character is skipped, and no entry will be
/// returned. /// returned.
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn load_character_list(player_uuid: &str, db_dir: &str) -> CharacterListResult { pub fn load_character_list(player_uuid: &str, db_dir: &str) -> CharacterListResult {
let data = schema::character::dsl::character let data = schema::character::dsl::character
.filter(schema::character::player_uuid.eq(player_uuid)) .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() .build()
}, },
|data| comp::Loadout::from(data), comp::Loadout::from,
); );
CharacterItem { CharacterItem {

View File

@ -44,7 +44,6 @@ impl<'a> System<'a> for Sys {
ReadTrackers<'a>, ReadTrackers<'a>,
); );
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
fn run( fn run(
&mut self, &mut self,
( (
@ -163,7 +162,7 @@ impl<'a> System<'a> for Sys {
region.entities(), region.entities(),
deleted_entities deleted_entities
.take_deleted_in_region(key) .take_deleted_in_region(key)
.unwrap_or_else(|| Vec::new()), .unwrap_or_default(),
); );
let entity_sync_msg = ServerMsg::EntitySync(entity_sync_package); let entity_sync_msg = ServerMsg::EntitySync(entity_sync_package);
let comp_sync_msg = ServerMsg::CompSync(comp_sync_package); let comp_sync_msg = ServerMsg::CompSync(comp_sync_package);

View File

@ -39,7 +39,6 @@ pub struct CombatEventMapper {
} }
impl EventMapper for 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) { fn maintain(&mut self, state: &State, player_entity: EcsEntity, triggers: &SfxTriggers) {
let ecs = state.ecs(); let ecs = state.ecs();
@ -63,10 +62,7 @@ impl EventMapper for CombatEventMapper {
}) })
{ {
if let Some(character) = character { if let Some(character) = character {
let state = self let state = self.event_history.entry(entity).or_default();
.event_history
.entry(entity)
.or_insert_with(|| PreviousEntityState::default());
let mapped_event = Self::map_event(character, state, loadout); let mapped_event = Self::map_event(character, state, loadout);

View File

@ -36,7 +36,6 @@ pub struct MovementEventMapper {
} }
impl EventMapper for 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) { fn maintain(&mut self, state: &State, player_entity: EcsEntity, triggers: &SfxTriggers) {
let ecs = state.ecs(); let ecs = state.ecs();
@ -62,10 +61,7 @@ impl EventMapper for MovementEventMapper {
}) })
{ {
if let Some(character) = character { if let Some(character) = character {
let state = self let state = self.event_history.entry(entity).or_default();
.event_history
.entry(entity)
.or_insert_with(|| PreviousEntityState::default());
let mapped_event = match body { let mapped_event = match body {
Body::Humanoid(_) => Self::map_movement_event(character, physics, state, vel.0), Body::Humanoid(_) => Self::map_movement_event(character, physics, state, vel.0),

View File

@ -162,7 +162,6 @@ pub struct MainMenuUi {
} }
impl MainMenuUi { impl MainMenuUi {
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn new(global_state: &mut GlobalState) -> Self { pub fn new(global_state: &mut GlobalState) -> Self {
let window = &mut global_state.window; let window = &mut global_state.window;
let networking = &global_state.settings.networking; let networking = &global_state.settings.networking;
@ -216,7 +215,8 @@ impl MainMenuUi {
server_address: networking server_address: networking
.servers .servers
.get(networking.default_server) .get(networking.default_server)
.map_or_else(|| String::new(), |address| address.clone()), .cloned()
.unwrap_or_default(),
popup: None, popup: None,
connecting: None, connecting: None,
show_servers: false, show_servers: false,

View File

@ -211,7 +211,7 @@ impl<'a, V: RectRasterableVol<Vox = Block> + ReadVol + Debug>
#[allow(clippy::needless_range_loop)] // TODO: Pending review in #587 #[allow(clippy::needless_range_loop)] // TODO: Pending review in #587
#[allow(clippy::or_fun_call)] // 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::panic_params)] // TODO: Pending review in #587
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
fn generate_mesh( fn generate_mesh(
&'a self, &'a self,
range: Self::Supplement, range: Self::Supplement,
@ -343,7 +343,7 @@ impl<'a, V: RectRasterableVol<Vox = Block> + ReadVol + Debug>
maybe_block maybe_block
.filter(|vox| vox.is_opaque() && (!neighbour || vox.is_blended())) .filter(|vox| vox.is_opaque() && (!neighbour || vox.is_blended()))
.and_then(|vox| vox.get_color()) .and_then(|vox| vox.get_color())
.map(|col| Rgba::from_opaque(col)) .map(Rgba::from_opaque)
.unwrap_or(Rgba::zero()) .unwrap_or(Rgba::zero())
}; };

View File

@ -18,7 +18,7 @@ impl<T: Copy + gfx::traits::Pod> Consts<T> {
} }
/// Update the GPU-side value represented by this constant handle. /// Update the GPU-side value represented by this constant handle.
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn update( pub fn update(
&mut self, &mut self,
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>, encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
@ -26,6 +26,6 @@ impl<T: Copy + gfx::traits::Pod> Consts<T> {
) -> Result<(), RenderError> { ) -> Result<(), RenderError> {
encoder encoder
.update_buffer(&self.buf, vals, 0) .update_buffer(&self.buf, vals, 0)
.map_err(|err| RenderError::UpdateError(err)) .map_err(RenderError::UpdateError)
} }
} }

View File

@ -12,18 +12,16 @@ pub struct Instances<T: Copy + gfx::traits::Pod> {
} }
impl<T: Copy + gfx::traits::Pod> Instances<T> { impl<T: Copy + gfx::traits::Pod> Instances<T> {
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Result<Self, RenderError> { pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Result<Self, RenderError> {
Ok(Self { Ok(Self {
ibuf: factory ibuf: factory
.create_buffer(len, Role::Vertex, Usage::Dynamic, Bind::TRANSFER_DST) .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() } pub fn count(&self) -> usize { self.ibuf.len() }
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn update( pub fn update(
&mut self, &mut self,
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>, encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
@ -31,6 +29,6 @@ impl<T: Copy + gfx::traits::Pod> Instances<T> {
) -> Result<(), RenderError> { ) -> Result<(), RenderError> {
encoder encoder
.update_buffer(&self.ibuf, instances, 0) .update_buffer(&self.ibuf, instances, 0)
.map_err(|err| RenderError::UpdateError(err)) .map_err(RenderError::UpdateError)
} }
} }

View File

@ -30,12 +30,11 @@ pub struct DynamicModel<P: Pipeline> {
} }
impl<P: Pipeline> DynamicModel<P> { impl<P: Pipeline> DynamicModel<P> {
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn new(factory: &mut gfx_backend::Factory, size: usize) -> Result<Self, RenderError> { pub fn new(factory: &mut gfx_backend::Factory, size: usize) -> Result<Self, RenderError> {
Ok(Self { Ok(Self {
vbuf: factory vbuf: factory
.create_buffer(size, Role::Vertex, Usage::Dynamic, Bind::empty()) .create_buffer(size, Role::Vertex, Usage::Dynamic, Bind::empty())
.map_err(|err| RenderError::BufferCreationError(err))?, .map_err(RenderError::BufferCreationError)?,
}) })
} }
@ -48,7 +47,6 @@ impl<P: Pipeline> DynamicModel<P> {
} }
} }
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn update( pub fn update(
&self, &self,
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>, encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
@ -57,6 +55,6 @@ impl<P: Pipeline> DynamicModel<P> {
) -> Result<(), RenderError> { ) -> Result<(), RenderError> {
encoder encoder
.update_buffer(&self.vbuf, mesh.vertices(), offset) .update_buffer(&self.vbuf, mesh.vertices(), offset)
.map_err(|err| RenderError::UpdateError(err)) .map_err(RenderError::UpdateError)
} }
} }

View File

@ -26,7 +26,6 @@ where
F::Channel: gfx::format::TextureChannel, F::Channel: gfx::format::TextureChannel,
<F::Surface as gfx::format::SurfaceTyped>::DataType: Copy, <F::Surface as gfx::format::SurfaceTyped>::DataType: Copy,
{ {
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn new( pub fn new(
factory: &mut gfx_backend::Factory, factory: &mut gfx_backend::Factory,
image: &DynamicImage, image: &DynamicImage,
@ -43,7 +42,7 @@ where
gfx::texture::Mipmap::Provided, gfx::texture::Mipmap::Provided,
&[&image.raw_pixels()], &[&image.raw_pixels()],
) )
.map_err(|err| RenderError::CombinedError(err))?; .map_err(RenderError::CombinedError)?;
Ok(Self { Ok(Self {
tex, tex,
@ -89,7 +88,7 @@ where
/// Update a texture with the given data (used for updating the glyph cache /// Update a texture with the given data (used for updating the glyph cache
/// texture). /// texture).
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn update( pub fn update(
&self, &self,
encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>, encoder: &mut gfx::Encoder<gfx_backend::Resources, gfx_backend::CommandBuffer>,
@ -111,7 +110,7 @@ where
.update_texture::<<F as gfx::format::Formatted>::Surface, F>( .update_texture::<<F as gfx::format::Formatted>::Surface, F>(
&self.tex, None, info, data, &self.tex, None, info, data,
) )
.map_err(|err| RenderError::TexUpdateError(err)) .map_err(RenderError::TexUpdateError)
} }
/// Get dimensions of the represented image. /// Get dimensions of the represented image.

View File

@ -248,7 +248,7 @@ fn sprite_config_for(kind: BlockKind) -> Option<SpriteConfig> {
/// Function executed by worker threads dedicated to chunk meshing. /// Function executed by worker threads dedicated to chunk meshing.
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug>( fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug>(
pos: Vec2<i32>, pos: Vec2<i32>,
z_bounds: (f32, f32), z_bounds: (f32, f32),
@ -292,7 +292,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug>(
instances instances
.entry((block.kind(), seed as usize % cfg.variations)) .entry((block.kind(), seed as usize % cfg.variations))
.or_insert_with(|| Vec::new()) .or_insert_with(Vec::new)
.push(instance); .push(instance);
} }
} }

View File

@ -676,7 +676,7 @@ pub struct Settings {
impl Default for Settings { impl Default for Settings {
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::or_fun_call)] // TODO: Pending review in #587
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
fn default() -> Self { fn default() -> Self {
let user_dirs = UserDirs::new().expect("System's $HOME directory path not found!"); 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(user_dirs.picture_dir().map(|dir| dir.join("veloren")))
.or(std::env::current_exe() .or(std::env::current_exe()
.ok() .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"); .expect("Couldn't choose a place to store the screenshots");
Settings { Settings {

View File

@ -4,7 +4,6 @@ use vek::*;
#[derive(Clone)] #[derive(Clone)]
pub struct Event(pub Input); pub struct Event(pub Input);
impl Event { impl Event {
#[allow(clippy::redundant_closure)] // TODO: Pending review in #587
pub fn try_from( pub fn try_from(
event: glutin::Event, event: glutin::Event,
window: &glutin::ContextWrapper<glutin::PossiblyCurrent, winit::Window>, window: &glutin::ContextWrapper<glutin::PossiblyCurrent, winit::Window>,
@ -23,7 +22,7 @@ impl Event {
fn hidpi_factor(&self) -> f32 { winit::Window::get_hidpi_factor(&self.0) as _ } 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 { pub fn is_keyboard_or_mouse(&self) -> bool {

View File

@ -305,7 +305,7 @@ pub struct WorldSim {
impl WorldSim { impl WorldSim {
#[allow(clippy::if_same_then_else)] // TODO: Pending review in #587 #[allow(clippy::if_same_then_else)] // TODO: Pending review in #587
#[allow(clippy::let_and_return)] // 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 { pub fn generate(seed: u32, opts: WorldOpts) -> Self {
let mut rng = ChaChaRng::from_seed(seed_expan::rng_state(seed)); 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 // NOTE: Change 1.0 to 4.0, while multiplying grid_size by 4, for a 4x
@ -976,22 +976,22 @@ impl WorldSim {
// varying conditions // varying conditions
&rock_strength_nz, &rock_strength_nz,
// initial conditions // initial conditions
|posi| alt_func(posi), alt_func,
|posi| alt_func(posi) - if is_ocean_fn(posi) { 0.0 } else { 0.0 }, |posi| alt_func(posi) - if is_ocean_fn(posi) { 0.0 } else { 0.0 },
is_ocean_fn, is_ocean_fn,
// empirical constants // empirical constants
uplift_fn, uplift_fn,
|posi| n_func(posi), n_func,
|posi| theta_func(posi), theta_func,
|posi| kf_func(posi), kf_func,
|posi| kd_func(posi), kd_func,
|posi| g_func(posi), g_func,
|posi| epsilon_0_func(posi), epsilon_0_func,
|posi| alpha_func(posi), alpha_func,
// scaling factors // scaling factors
|n| height_scale(n), height_scale,
k_d_scale(n_approx), k_d_scale(n_approx),
|q| k_da_scale(q), k_da_scale,
); );
// Quick "small scale" erosion cycle in order to lower extreme angles. // Quick "small scale" erosion cycle in order to lower extreme angles.
@ -1004,16 +1004,16 @@ impl WorldSim {
|posi| basement[posi] as f32, |posi| basement[posi] as f32,
is_ocean_fn, is_ocean_fn,
|posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t), |posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t),
|posi| n_func(posi), n_func,
|posi| theta_func(posi), theta_func,
|posi| kf_func(posi), kf_func,
|posi| kd_func(posi), kd_func,
|posi| g_func(posi), g_func,
|posi| epsilon_0_func(posi), epsilon_0_func,
|posi| alpha_func(posi), alpha_func,
|n| height_scale(n), height_scale,
k_d_scale(n_approx), k_d_scale(n_approx),
|q| k_da_scale(q), k_da_scale,
) )
}; };
@ -1071,16 +1071,16 @@ impl WorldSim {
|posi| basement[posi] as f32, |posi| basement[posi] as f32,
is_ocean_fn, is_ocean_fn,
|posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t), |posi| uplift_fn(posi) * (1.0 / max_erosion_per_delta_t),
|posi| n_func(posi), n_func,
|posi| theta_func(posi), theta_func,
|posi| kf_func(posi), kf_func,
|posi| kd_func(posi), kd_func,
|posi| g_func(posi), g_func,
|posi| epsilon_0_func(posi), epsilon_0_func,
|posi| alpha_func(posi), alpha_func,
|n| height_scale(n), height_scale,
k_d_scale(n_approx), k_d_scale(n_approx),
|q| k_da_scale(q), k_da_scale,
) )
}; };