From cb80f1cefa49d23aedf7980a33fd3c7eee543779 Mon Sep 17 00:00:00 2001 From: louis-e <44675238+louis-e@users.noreply.github.com> Date: Sun, 19 Apr 2026 01:17:42 +0200 Subject: [PATCH] Fix clippy warnings for Rust 1.95: collapsible_match, unnecessary_cast, sort_by_key, explicit_counter_loop --- src/element_processing/landuse.rs | 30 ++++++++++--------------- src/element_processing/natural.rs | 19 +++++++--------- src/floodfill_cache.rs | 13 ++++++----- src/ground_generation.rs | 10 ++++----- src/map_renderer.rs | 2 +- src/map_transformation/transform_map.rs | 5 +---- src/world_editor/java.rs | 2 +- 7 files changed, 34 insertions(+), 47 deletions(-) diff --git a/src/element_processing/landuse.rs b/src/element_processing/landuse.rs index daa7d03..3ff5c0b 100644 --- a/src/element_processing/landuse.rs +++ b/src/element_processing/landuse.rs @@ -135,8 +135,8 @@ pub fn generate_landuse( // Add specific features for different landuse types match landuse_tag.as_str() { - "cemetery" => { - if (x % 3 == 0) && (z % 3 == 0) { + "cemetery" + if (x % 3 == 0) && (z % 3 == 0) => { let random_choice: i32 = rng.random_range(0..100); if random_choice < 15 { // Place graves @@ -168,9 +168,8 @@ pub fn generate_landuse( editor.set_block(LARGE_FERN_UPPER, x, 2, z, None, None); } } - } - "forest" => { - if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) { + "forest" + if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) => { let random_choice: i32 = rng.random_range(0..30); if random_choice == 20 { let tree_type = *trees_ok_to_generate @@ -200,10 +199,9 @@ pub fn generate_landuse( } } } - } - "farmland" => { + "farmland" // Check if the current block is not water or another undesired block - if !editor.check_for_block(x, 0, z, Some(&[WATER])) { + if !editor.check_for_block(x, 0, z, Some(&[WATER])) => { if x % 9 == 0 && z % 9 == 0 { // Place water in dot pattern editor.set_block(WATER, x, 0, z, Some(&[FARMLAND]), None); @@ -222,7 +220,6 @@ pub fn generate_landuse( } } } - } "construction" => { let random_choice: i32 = rng.random_range(0..1501); if random_choice < 15 { @@ -295,8 +292,8 @@ pub fn generate_landuse( editor.set_block(COBBLESTONE, x, 0, z, None, Some(&[SPONGE])); } } - "grass" => { - if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) { + "grass" + if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) => { match rng.random_range(0..200) { 0 => editor.set_block(OAK_LEAVES, x, 1, z, None, None), 1..=8 => editor.set_block(FERN, x, 1, z, None, None), @@ -304,9 +301,8 @@ pub fn generate_landuse( _ => {} } } - } - "greenfield" => { - if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) { + "greenfield" + if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) => { match rng.random_range(0..200) { 0 => editor.set_block(OAK_LEAVES, x, 1, z, None, None), 1..=2 => editor.set_block(FERN, x, 1, z, None, None), @@ -314,9 +310,8 @@ pub fn generate_landuse( _ => {} } } - } - "meadow" => { - if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) { + "meadow" + if editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK])) => { let random_choice: i32 = rng.random_range(0..1001); if random_choice < 5 { Tree::create(editor, (x, 1, z), Some(building_footprints)); @@ -333,7 +328,6 @@ pub fn generate_landuse( editor.set_block(GRASS, x, 1, z, None, None); } } - } "orchard" => { if x % 18 == 0 && z % 10 == 0 { Tree::create(editor, (x, 1, z), Some(building_footprints)); diff --git a/src/element_processing/natural.rs b/src/element_processing/natural.rs index 463ab5e..97c3ff4 100644 --- a/src/element_processing/natural.rs +++ b/src/element_processing/natural.rs @@ -300,17 +300,14 @@ pub fn generate_natural( editor.set_block(GRASS, x, 1, z, None, None); } } - "sand" => { + "sand" if editor.check_for_block(x, 0, z, Some(&[SAND])) - && rng.random_range(0..100) == 1 - { - editor.set_block(DEAD_BUSH, x, 1, z, None, None); - } + && rng.random_range(0..100) == 1 => + { + editor.set_block(DEAD_BUSH, x, 1, z, None, None); } - "shoal" => { - if rng.random_bool(0.05) { - editor.set_block(WATER, x, 0, z, Some(&[SAND, GRAVEL]), None); - } + "shoal" if rng.random_bool(0.05) => { + editor.set_block(WATER, x, 0, z, Some(&[SAND, GRAVEL]), None); } "wetland" => { if let Some(wetland_type) = element.tags().get("wetland") { @@ -406,8 +403,8 @@ pub fn generate_natural( let cluster_size = rng.random_range(5..=10); // Create cluster around current position - for dx in -(cluster_size as i32)..=(cluster_size as i32) { - for dz in -(cluster_size as i32)..=(cluster_size as i32) { + for dx in -cluster_size..=cluster_size { + for dz in -cluster_size..=cluster_size { let cluster_x = x + dx; let cluster_z = z + dz; diff --git a/src/floodfill_cache.rs b/src/floodfill_cache.rs index d4aac37..4a9183c 100644 --- a/src/floodfill_cache.rs +++ b/src/floodfill_cache.rs @@ -379,12 +379,13 @@ impl FloodFillCache { for element in elements { match element { - ProcessedElement::Way(way) => { - if way.tags.contains_key("building") || way.tags.contains_key("building:part") { - if let Some(cached) = self.way_cache.get(&way.id) { - for &(x, z) in cached { - footprints.set(x, z); - } + ProcessedElement::Way(way) + if way.tags.contains_key("building") + || way.tags.contains_key("building:part") => + { + if let Some(cached) = self.way_cache.get(&way.id) { + for &(x, z) in cached { + footprints.set(x, z); } } } diff --git a/src/ground_generation.rs b/src/ground_generation.rs index 153c2ae..8233f17 100644 --- a/src/ground_generation.rs +++ b/src/ground_generation.rs @@ -470,7 +470,7 @@ pub fn generate_ground_layer( ); } } - land_cover::LC_CROPLAND => { + land_cover::LC_CROPLAND // Only place crops if the ground is actually farmland if editor.check_for_block_absolute( x, @@ -478,7 +478,7 @@ pub fn generate_ground_layer( z, Some(&[FARMLAND]), None, - ) { + ) => { if x % 9 == 0 && z % 9 == 0 { editor.set_block_absolute( WATER, @@ -512,7 +512,6 @@ pub fn generate_ground_layer( ); } } - } land_cover::LC_WETLAND | land_cover::LC_MANGROVES if ground_is_natural => { @@ -555,9 +554,9 @@ pub fn generate_ground_layer( ); } } - land_cover::LC_BARE if ground_is_natural => { + land_cover::LC_BARE if ground_is_natural // Sparse dead bushes - if rng.random_range(0..100) == 0 { + && rng.random_range(0..100) == 0 => { editor.set_block_absolute( DEAD_BUSH, x, @@ -567,7 +566,6 @@ pub fn generate_ground_layer( None, ); } - } _ => {} } } diff --git a/src/map_renderer.rs b/src/map_renderer.rs index 5ad4cdb..e19cbf1 100644 --- a/src/map_renderer.rs +++ b/src/map_renderer.rs @@ -275,7 +275,7 @@ fn get_sorted_sections<'a>(sections: &[&'a Value]) -> Vec<(i8, &'a Value)> { }) .collect(); - sorted.sort_by(|a, b| b.0.cmp(&a.0)); + sorted.sort_by_key(|b| std::cmp::Reverse(b.0)); sorted } diff --git a/src/map_transformation/transform_map.rs b/src/map_transformation/transform_map.rs index e2c1f42..bd5afe0 100644 --- a/src/map_transformation/transform_map.rs +++ b/src/map_transformation/transform_map.rs @@ -25,17 +25,14 @@ pub fn transform_map( }); let nop: usize = ops.len(); - let mut iop: usize = 1; let progress_increment_prcs: f64 = 5.0 / nop as f64; - for op in ops { + for (iop, op) in (1..).zip(ops) { let current_progress_prcs = 20.0 + (iop as f64 * progress_increment_prcs); //let message = format!("Applying operation: {}, {}/{}", op.repr(), iop, nop); emit_gui_progress_update(current_progress_prcs, ""); - iop += 1; - op.operate(elements, xzbbox, ground); } diff --git a/src/world_editor/java.rs b/src/world_editor/java.rs index 5fabb75..bff6f15 100644 --- a/src/world_editor/java.rs +++ b/src/world_editor/java.rs @@ -450,7 +450,7 @@ fn compute_heightmaps(sections: &[Section], min_section_y: i8, total_height: i32 .collect(); // Sort by Y descending so we scan top-down - metas.sort_by(|a, b| b.y.cmp(&a.y)); + metas.sort_by_key(|b| std::cmp::Reverse(b.y)); let mut heights = [0i32; 256]; // 16x16 grid, Z-major order let min_block_y = min_section_y as i32 * 16;