From 5cc2fc81820fe76eebf9b0080c6908e755d4a58c Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Thu, 15 Jul 2021 12:57:09 +0200 Subject: [PATCH] Resolve all '#[allow(clippy::or_fun_call))]' error supressions --- voxygen/src/menu/main/client_init.rs | 1 - voxygen/src/mesh/segment.rs | 24 +++++++++++-------- voxygen/src/mesh/terrain.rs | 4 ++-- voxygen/src/render/pipelines/mod.rs | 3 +-- voxygen/src/scene/figure/mod.rs | 9 ++----- voxygen/src/scene/terrain.rs | 1 - voxygen/src/window.rs | 1 - world/examples/settlement_viewer.rs | 3 +-- world/src/civ/mod.rs | 3 +-- world/src/lib.rs | 3 +-- world/src/site/castle/mod.rs | 1 - .../src/site/settlement/building/skeleton.rs | 3 +-- world/src/site/settlement/mod.rs | 1 - world/src/site2/plot/dungeon.rs | 1 - 14 files changed, 23 insertions(+), 35 deletions(-) diff --git a/voxygen/src/menu/main/client_init.rs b/voxygen/src/menu/main/client_init.rs index d737c66736..927ad74bff 100644 --- a/voxygen/src/menu/main/client_init.rs +++ b/voxygen/src/menu/main/client_init.rs @@ -44,7 +44,6 @@ pub struct ClientInit { } impl ClientInit { #[allow(clippy::op_ref)] // TODO: Pending review in #587 - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn new( connection_args: ConnectionArgs, username: String, diff --git a/voxygen/src/mesh/segment.rs b/voxygen/src/mesh/segment.rs index 0de1b21701..f2cc9485d9 100644 --- a/voxygen/src/mesh/segment.rs +++ b/voxygen/src/mesh/segment.rs @@ -15,7 +15,6 @@ use vek::*; // /// NOTE: bone_idx must be in [0, 15] (may be bumped to [0, 31] at some // /// point). -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 // TODO: this function name... pub fn generate_mesh_base_vol_terrain<'a: 'b, 'b, V: 'a>( vol: V, @@ -65,7 +64,9 @@ where let get_opacity = |vol: &mut V, pos: Vec3| vol.get(pos).map_or(true, |vox| vox.is_empty()); let should_draw = |vol: &mut V, pos: Vec3, delta: Vec3, uv| { should_draw_greedy(pos, delta, uv, |vox| { - vol.get(vox).map(|vox| *vox).unwrap_or(Cell::empty()) + vol.get(vox) + .map(|vox| *vox) + .unwrap_or_else(|_| Cell::empty()) }) }; let create_opaque = |atlas_pos, pos, norm| { @@ -97,7 +98,9 @@ where let (glowy, shiny) = cell .map(|c| (c.is_glowy(), c.is_shiny())) .unwrap_or_default(); - let col = cell.and_then(|vox| vox.get_color()).unwrap_or(Rgb::zero()); + let col = cell + .and_then(|vox| vox.get_color()) + .unwrap_or_else(Rgb::zero); TerrainVertex::make_col_light_figure(light, glowy, shiny, col) }, }); @@ -111,7 +114,6 @@ where (Mesh::new(), Mesh::new(), Mesh::new(), bounds) } -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn generate_mesh_base_vol_sprite<'a: 'b, 'b, V: 'a>( vol: V, (greedy, opaque_mesh, vertical_stripes): ( @@ -162,7 +164,7 @@ where for y in -1..greedy_size.y + 1 { for z in -1..greedy_size.z + 1 { let wpos = lower_bound + Vec3::new(x, y, z); - let block = vol.get(wpos).map(|b| *b).unwrap_or(Cell::empty()); + let block = vol.get(wpos).map(|b| *b).unwrap_or_else(|_| Cell::empty()); flat[i] = block; i += 1; } @@ -197,8 +199,9 @@ where } }; let get_glow = |_flat: &mut _, _pos: Vec3| 0.0; - let get_color = - move |flat: &mut _, pos: Vec3| flat_get(flat, pos).get_color().unwrap_or(Rgb::zero()); + let get_color = move |flat: &mut _, pos: Vec3| { + flat_get(flat, pos).get_color().unwrap_or_else(Rgb::zero) + }; let get_opacity = move |flat: &mut _, pos: Vec3| flat_get(flat, pos).is_empty(); let should_draw = move |flat: &mut _, pos: Vec3, delta: Vec3, uv| { should_draw_greedy_ao(vertical_stripes, pos, delta, uv, |vox| flat_get(flat, vox)) @@ -238,7 +241,6 @@ where (Mesh::new(), Mesh::new(), Mesh::new(), ()) } -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn generate_mesh_base_vol_particle<'a: 'b, 'b, V: 'a>( vol: V, greedy: &'b mut GreedyMesh<'a>, @@ -285,12 +287,14 @@ where vol.get(pos) .ok() .and_then(|vox| vox.get_color()) - .unwrap_or(Rgb::zero()) + .unwrap_or_else(Rgb::zero) }; let get_opacity = |vol: &mut V, pos: Vec3| vol.get(pos).map_or(true, |vox| vox.is_empty()); let should_draw = |vol: &mut V, pos: Vec3, delta: Vec3, uv| { should_draw_greedy(pos, delta, uv, |vox| { - vol.get(vox).map(|vox| *vox).unwrap_or(Cell::empty()) + vol.get(vox) + .map(|vox| *vox) + .unwrap_or_else(|_| Cell::empty()) }) }; let create_opaque = |_atlas_pos, pos: Vec3, norm| ParticleVertex::new(pos, norm); diff --git a/voxygen/src/mesh/terrain.rs b/voxygen/src/mesh/terrain.rs index b90f5e440b..5561ef5b96 100644 --- a/voxygen/src/mesh/terrain.rs +++ b/voxygen/src/mesh/terrain.rs @@ -228,7 +228,6 @@ fn calc_light + ReadVol + Debug>( #[allow(clippy::many_single_char_names)] #[allow(clippy::type_complexity)] #[allow(clippy::needless_range_loop)] // TODO: Pending review in #587 -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn generate_mesh<'a, V: RectRasterableVol + ReadVol + Debug + 'static>( vol: &'a VolGrid2d, (range, max_texture_size, _boi): (Aabb, Vec2, &'a BlocksOfInterest), @@ -381,7 +380,8 @@ pub fn generate_mesh<'a, V: RectRasterableVol + ReadVol + Debug + ' } }; let get_glow = |_: &mut (), pos: Vec3| glow(pos + range.min); - let get_color = |_: &mut (), pos: Vec3| flat_get(pos).get_color().unwrap_or(Rgb::zero()); + let get_color = + |_: &mut (), pos: Vec3| flat_get(pos).get_color().unwrap_or_else(Rgb::zero); let get_opacity = |_: &mut (), pos: Vec3| !flat_get(pos).is_opaque(); let flat_get = |pos| flat_get(pos); let should_draw = |_: &mut (), pos: Vec3, delta: Vec3, _uv| { diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 846a4d7339..592d1da64d 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -80,7 +80,6 @@ pub struct Shadow { impl Globals { /// Create global consts from the provided parameters. - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::too_many_arguments)] // TODO: Pending review in #587 pub fn new( view_mat: Mat4, @@ -140,7 +139,7 @@ impl Globals { medium: [if medium.is_liquid() { 1 } else { 0 }; 4], select_pos: select_pos .map(|sp| Vec4::from(sp) + Vec4::unit_w()) - .unwrap_or(Vec4::zero()) + .unwrap_or_else(Vec4::zero) .into_array(), gamma_exposure: [gamma, exposure, 0.0, 0.0], ambiance, diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 64478e0acc..247f92aec6 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -36,7 +36,6 @@ use common::{ resources::DeltaTime, states::utils::StageSection, terrain::TerrainChunk, - util::Dir, vol::RectRasterableVol, }; use common_base::span; @@ -488,8 +487,6 @@ impl FigureMgr { } } - #[allow(clippy::or_fun_call)] - // TODO: Pending review in #587 pub fn maintain( &mut self, renderer: &mut Renderer, @@ -617,9 +614,7 @@ impl FigureMgr { // Velocity relative to the current ground let rel_vel = anim::vek::Vec3::::from(vel.0 - physics.ground_vel); - let look_dir = controller - .map(|c| c.inputs.look_dir) - .unwrap_or(Dir::default()); + let look_dir = controller.map(|c| c.inputs.look_dir).unwrap_or_default(); let is_player = scene_data.player_entity == entity; let player_camera_mode = if is_player { camera_mode @@ -723,7 +718,7 @@ impl FigureMgr { (c / (1.0 + DAMAGE_FADE_COEFFICIENT * h.last_change.0)) as f32 }) }) - .unwrap_or(vek::Rgba::broadcast(1.0)) + .unwrap_or_else(|| vek::Rgba::broadcast(1.0)) // Highlight targeted collectible entities * if item.is_some() && scene_data.target_entity.map_or(false, |e| e == entity) { vek::Rgba::new(5.0, 5.0, 5.0, 1.0) diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 36495d259c..ed68b10646 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -166,7 +166,6 @@ impl assets::Asset for SpriteSpec { } /// Function executed by worker threads dedicated to chunk meshing. -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 /// skip_remesh is either None (do the full remesh, including recomputing the /// light map), or Some((light_map, glow_map)). diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index dd26add1de..e641f6a80b 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -1400,7 +1400,6 @@ impl Window { pub fn needs_refresh_resize(&mut self) { self.needs_refresh_resize = true; } - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn logical_size(&self) -> Vec2 { let (w, h) = self .window diff --git a/world/examples/settlement_viewer.rs b/world/examples/settlement_viewer.rs index 18b6fdc90c..d2c311827b 100644 --- a/world/examples/settlement_viewer.rs +++ b/world/examples/settlement_viewer.rs @@ -5,7 +5,6 @@ use veloren_world::{index::Index, site::Settlement, IndexRef}; const W: usize = 640; const H: usize = 480; -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 fn main() { let seed = 1337; let index = &Index::new(seed); @@ -32,7 +31,7 @@ fn main() { let color = settlement .get_color(index, pos.map(|e| e.floor() as i32)) - .unwrap_or(Rgb::new(35, 50, 20)); + .unwrap_or_else(|| Rgb::new(35, 50, 20)); buf[j * W + i] = u32::from_le_bytes([color.b, color.g, color.r, 255]); } diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index c4f6240e4c..8039a8bfd3 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -819,7 +819,6 @@ fn loc_suitable_for_site(sim: &WorldSim, loc: Vec2) -> bool { } /// Attempt to search for a location that's suitable for site construction -#[allow(clippy::or_fun_call)] // TODO: Pending review in #587 fn find_site_loc( ctx: &mut GenCtx, near: Option<(Vec2, f32)>, @@ -833,7 +832,7 @@ fn find_site_loc( origin + (Vec2::new(ctx.rng.gen_range(-1.0..1.0), ctx.rng.gen_range(-1.0..1.0)) .try_normalized() - .unwrap_or(Vec2::zero()) + .unwrap_or_else(Vec2::zero) * ctx.rng.gen::() * dist) .map(|e| e as i32) diff --git a/world/src/lib.rs b/world/src/lib.rs index 0dc4451370..dd7a5b9708 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -224,7 +224,6 @@ impl World { + 0.5 } - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 #[allow(clippy::eval_order_dependence)] #[allow(clippy::result_unit_err)] pub fn generate_chunk( @@ -252,7 +251,7 @@ impl World { .get(grid_border + TerrainChunkSize::RECT_SIZE.map(|e| e as i32) / 2) .and_then(|zcache| zcache.as_ref()) .map(|zcache| zcache.sample.stone_col) - .unwrap_or(index.colors.deep_stone_color.into()), + .unwrap_or_else(|| index.colors.deep_stone_color.into()), ); let water = Block::new(BlockKind::Water, Rgb::zero()); diff --git a/world/src/site/castle/mod.rs b/world/src/site/castle/mod.rs index 8824098190..655138e884 100644 --- a/world/src/site/castle/mod.rs +++ b/world/src/site/castle/mod.rs @@ -430,7 +430,6 @@ impl Castle { } } - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn apply_supplement<'a>( &'a self, // NOTE: Used only for dynamic elements like chests and entities! diff --git a/world/src/site/settlement/building/skeleton.rs b/world/src/site/settlement/building/skeleton.rs index 01827a958d..adef23b829 100644 --- a/world/src/site/settlement/building/skeleton.rs +++ b/world/src/site/settlement/building/skeleton.rs @@ -73,7 +73,6 @@ impl Skeleton { } #[allow(clippy::logic_bug)] // TODO: Pending review in #587 - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn sample_closest( &self, pos: Vec3, @@ -123,6 +122,6 @@ impl Skeleton { .or(Some((dist_locus, new_bm))); } }); - min.map(|(_, bm)| bm).unwrap_or(BlockMask::nothing()) + min.map(|(_, bm)| bm).unwrap_or_else(BlockMask::nothing) } } diff --git a/world/src/site/settlement/mod.rs b/world/src/site/settlement/mod.rs index 8fce212e14..21fcb1baa8 100644 --- a/world/src/site/settlement/mod.rs +++ b/world/src/site/settlement/mod.rs @@ -265,7 +265,6 @@ impl Settlement { } } - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn place_paths(&mut self, rng: &mut impl Rng) { const PATH_COUNT: usize = 6; diff --git a/world/src/site2/plot/dungeon.rs b/world/src/site2/plot/dungeon.rs index f85a16e0eb..06664180cd 100644 --- a/world/src/site2/plot/dungeon.rs +++ b/world/src/site2/plot/dungeon.rs @@ -128,7 +128,6 @@ impl Dungeon { pub fn difficulty(&self) -> u32 { self.difficulty } - #[allow(clippy::or_fun_call)] // TODO: Pending review in #587 pub fn apply_supplement<'a>( &'a self, // NOTE: Used only for dynamic elements like chests and entities!