From 201a5ac2c707878ccde55e22414c563fefb75073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Fri, 10 Dec 2021 11:36:46 +0100 Subject: [PATCH] stricten some rules and fix some clippy warnings --- clippy.toml | 4 ++-- common/net/src/lib.rs | 1 - common/net/src/sync/packet.rs | 1 + common/src/figure/mod.rs | 1 + common/src/lib.rs | 7 +----- common/src/region.rs | 24 ++++--------------- common/src/spiral.rs | 12 ++++++---- common/src/states/sprite_summon.rs | 2 +- voxygen/src/lib.rs | 6 +---- voxygen/src/render/mesh.rs | 1 + voxygen/src/scene/figure/cache.rs | 1 + .../examples/chunk_compression_benchmarks.rs | 3 +-- 12 files changed, 23 insertions(+), 40 deletions(-) diff --git a/clippy.toml b/clippy.toml index b7748bf6bd..5146b9297c 100644 --- a/clippy.toml +++ b/clippy.toml @@ -12,9 +12,9 @@ # ought to have many parameters too-many-arguments-threshold = 15 -# `many_single_char_names` often triggers for geometry or physics code with an +# `many_single_char_names` often triggers for geometry or physics code with an # associated diagram, where the short names are points in the diagram. -single-char-binding-names-threshold = 4294967295 +single-char-binding-names-threshold = 8 # `type_complexity` often triggers for the RHS of an associated type: it's # telling you that a type is complicated enough to need a name, at the point diff --git a/common/net/src/lib.rs b/common/net/src/lib.rs index 1c5bf4dace..671aa074d5 100644 --- a/common/net/src/lib.rs +++ b/common/net/src/lib.rs @@ -1,5 +1,4 @@ #![allow(incomplete_features)] -#![allow(clippy::new_without_default)] #![feature(generic_const_exprs, const_fn_floating_point_arithmetic)] pub mod msg; pub mod sync; diff --git a/common/net/src/sync/packet.rs b/common/net/src/sync/packet.rs index 31f787afea..d30a32ac59 100644 --- a/common/net/src/sync/packet.rs +++ b/common/net/src/sync/packet.rs @@ -137,6 +137,7 @@ pub struct CompSyncPackage { } impl CompSyncPackage

{ + #[allow(clippy::new_without_default)] pub fn new() -> Self { Self { comp_updates: Vec::new(), diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index 23d0d3dbe3..cbaaad9d89 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -113,6 +113,7 @@ impl Segment { pub struct DynaUnionizer(Vec<(Dyna, Vec3)>); impl DynaUnionizer { + #[allow(clippy::new_without_default)] pub fn new() -> Self { DynaUnionizer(Vec::new()) } #[must_use] diff --git a/common/src/lib.rs b/common/src/lib.rs index 44a651161b..ac0470bff2 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,12 +1,7 @@ #![deny(unsafe_code)] #![allow(incomplete_features)] #![type_length_limit = "1664759"] -#![allow( - clippy::erasing_op, - clippy::identity_op, - clippy::new_without_default, - clippy::option_map_unit_fn -)] +#![allow(clippy::option_map_unit_fn)] #![deny(clippy::clone_on_ref_ptr)] #![feature( associated_type_defaults, diff --git a/common/src/region.rs b/common/src/region.rs index d48c5f24f7..f8c1e7fda3 100644 --- a/common/src/region.rs +++ b/common/src/region.rs @@ -13,6 +13,7 @@ pub enum Event { } /// Region consisting of a bitset of entities within it +#[derive(Default)] pub struct Region { // Use specs bitset for simplicity (and joinability) bitset: BitSet, @@ -23,14 +24,6 @@ pub struct Region { events: Vec, } impl Region { - fn new() -> Self { - Self { - bitset: BitSet::new(), - neighbors: [None; 8], - events: Vec::new(), - } - } - /// Checks if the region contains no entities and no events fn removable(&self) -> bool { self.bitset.is_empty() && self.events.is_empty() } @@ -70,6 +63,7 @@ const NEIGHBOR_OFFSETS: [Vec2; 8] = [ Vec2::new(1, 1), ]; +#[derive(Default)] // TODO generic region size (16x16 for now) // TODO compare to sweep and prune approach /// A region system that tracks where entities are @@ -87,19 +81,11 @@ pub struct RegionMap { // (region, entity) entities_to_remove: Vec<(usize, u32)>, // Track the current tick, used to enable not checking everything every tick + // rate is dependent on the rate the caller calls region_manager.tick() tick: u64, } impl RegionMap { - pub fn new() -> Self { - Self { - regions: IndexMap::default(), - tracked_entities: BitSet::new(), - entities_to_move: Vec::new(), - entities_to_remove: Vec::new(), - // rate is dependent on the rate the caller calls region_manager.tick() - tick: 0, - } - } + pub fn new() -> Self { Self::default() } // TODO maintain within a system? // TODO special case large entities @@ -268,7 +254,7 @@ impl RegionMap { /// Adds a new region /// Returns the index of the region in the index map fn insert(&mut self, key: Vec2) -> usize { - let (index, old_region) = self.regions.insert_full(key, Region::new()); + let (index, old_region) = self.regions.insert_full(key, Region::default()); if old_region.is_some() { panic!("Inserted a region that already exists!!!(this should never need to occur"); } diff --git a/common/src/spiral.rs b/common/src/spiral.rs index e82f409f6c..a5c084ba31 100644 --- a/common/src/spiral.rs +++ b/common/src/spiral.rs @@ -9,19 +9,22 @@ pub struct Spiral2d { } impl Spiral2d { + #[allow(clippy::new_without_default)] /// Creates a new spiral starting at the origin pub fn new() -> Self { Self { layer: 0, i: 0 } } /// Creates an iterator over points in a spiral starting at the origin and /// going out to some radius - pub fn radius(self, radius: i32) -> impl Iterator> { - self.take((radius * 2 + 1).pow(2) as usize) + pub fn with_radius(radius: i32) -> impl Iterator> { + Self::new() + .take((radius * 2 + 1).pow(2) as usize) .filter(move |pos| pos.magnitude_squared() < (radius + 1).pow(2)) } /// Creates an iterator over points in the edge of a circle of some radius - pub fn edge_radius(self, radius: i32) -> impl Iterator> { - self.take((radius * 2 + 1).pow(2) as usize) + pub fn with_edge_radius(radius: i32) -> impl Iterator> { + Self::new() + .take((radius * 2 + 1).pow(2) as usize) .filter(move |pos| pos.magnitude_squared() < (radius + 1).pow(2)) .filter(move |pos| pos.magnitude_squared() >= radius.pow(2)) } @@ -30,6 +33,7 @@ impl Spiral2d { impl Iterator for Spiral2d { type Item = Vec2; + #[allow(clippy::erasing_op, clippy::identity_op)] fn next(&mut self) -> Option { let layer_size = (self.layer * 8 + 4 * self.layer.min(1) - 4).max(1); if self.i >= layer_size { diff --git a/common/src/states/sprite_summon.rs b/common/src/states/sprite_summon.rs index 01f11a432d..0483de1bce 100644 --- a/common/src/states/sprite_summon.rs +++ b/common/src/states/sprite_summon.rs @@ -85,7 +85,7 @@ impl CharacterBehavior for Data { // 1 added to make range correct, too lazy to add 1 to both variables above let radius = radius + 1; // Creates a spiral iterator for the newly achieved radius - let spiral = Spiral2d::new().edge_radius(radius); + let spiral = Spiral2d::with_edge_radius(radius); for point in spiral { // If square is not sparse, generate sprite if !thread_rng().gen_bool(self.static_data.sparseness) { diff --git a/voxygen/src/lib.rs b/voxygen/src/lib.rs index 699b9737b0..2c6c8d2196 100644 --- a/voxygen/src/lib.rs +++ b/voxygen/src/lib.rs @@ -1,10 +1,6 @@ #![deny(unsafe_code)] #![allow(incomplete_features)] -#![allow( - clippy::identity_op, - clippy::new_without_default, - clippy::option_map_unit_fn -)] +#![allow(clippy::identity_op, clippy::option_map_unit_fn)] #![deny(clippy::clone_on_ref_ptr)] #![feature( array_methods, diff --git a/voxygen/src/render/mesh.rs b/voxygen/src/render/mesh.rs index e05aab417a..b673ec01f2 100644 --- a/voxygen/src/render/mesh.rs +++ b/voxygen/src/render/mesh.rs @@ -15,6 +15,7 @@ impl Clone for Mesh { } impl Mesh { + #[allow(clippy::new_without_default)] /// Create a new `Mesh`. pub fn new() -> Self { Self { verts: Vec::new() } } diff --git a/voxygen/src/scene/figure/cache.rs b/voxygen/src/scene/figure/cache.rs index 50e3381c6a..84b441f5be 100644 --- a/voxygen/src/scene/figure/cache.rs +++ b/voxygen/src/scene/figure/cache.rs @@ -294,6 +294,7 @@ impl FigureModelCache where Skel::Body: BodySpec + Eq + Hash, { + #[allow(clippy::new_without_default)] pub fn new() -> Self { // NOTE: It might be better to bubble this error up rather than panicking. let manifests = ::load_spec().unwrap(); diff --git a/world/examples/chunk_compression_benchmarks.rs b/world/examples/chunk_compression_benchmarks.rs index 28e37d0c16..f4cb5fbf4e 100644 --- a/world/examples/chunk_compression_benchmarks.rs +++ b/world/examples/chunk_compression_benchmarks.rs @@ -747,8 +747,7 @@ fn main() { let mut total_timings: BTreeMap<&str, f32> = BTreeMap::new(); let mut count = 0; let mut volgrid = VolGrid2d::new().unwrap(); - for (i, spiralpos) in Spiral2d::new() - .radius(RADIUS) + for (i, spiralpos) in Spiral2d::with_radius(RADIUS) .map(|v| v + sitepos.as_()) .enumerate() {