From cf6a764aa4eedf31599a37894fef34b85548e7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Sat, 24 Sep 2022 00:15:24 +0200 Subject: [PATCH] update toolchain to `2022-09-23` --- common/src/bin/csv_export/main.rs | 30 +++++++++---------- common/src/comp/inventory/item/modular.rs | 6 ++-- common/src/comp/inventory/trade_pricing.rs | 8 ++--- common/src/comp/skillset/mod.rs | 2 +- common/src/lib.rs | 1 - common/src/path.rs | 2 +- common/src/terrain/map.rs | 2 +- common/src/volumes/chunk.rs | 6 ++-- common/systems/src/lib.rs | 2 +- rust-toolchain | 2 +- server/src/lib.rs | 1 - server/src/rtsim/entity.rs | 2 +- .../sys/agent/behavior_tree/interaction.rs | 6 +--- server/src/sys/sentinel.rs | 5 +--- voxygen/anim/src/lib.rs | 1 - voxygen/src/cmd.rs | 2 +- voxygen/src/hud/overhead.rs | 8 ++--- voxygen/src/profile.rs | 6 ++-- voxygen/src/render/pipelines/fluid.rs | 2 +- voxygen/src/render/pipelines/particle.rs | 1 + voxygen/src/render/pipelines/sprite.rs | 1 + voxygen/src/render/pipelines/terrain.rs | 9 ++---- voxygen/src/scene/lod.rs | 8 ++--- voxygen/src/scene/particle.rs | 6 +--- .../examples/chunk_compression_benchmarks.rs | 28 ++++++++--------- world/examples/dungeon_voxel_export.rs | 4 +-- world/examples/heightmap_visualization.rs | 4 +-- world/examples/world_block_statistics.rs | 2 +- world/src/lib.rs | 2 +- world/src/site/economy/context.rs | 7 +---- .../settlement/building/archetype/keep.rs | 7 +---- world/src/site2/plot/dungeon.rs | 6 ++-- world/src/site2/plot/house.rs | 1 + 33 files changed, 75 insertions(+), 105 deletions(-) diff --git a/common/src/bin/csv_export/main.rs b/common/src/bin/csv_export/main.rs index c04ee865a7..9ea38040bd 100644 --- a/common/src/bin/csv_export/main.rs +++ b/common/src/bin/csv_export/main.rs @@ -33,7 +33,7 @@ struct Cli { fn armor_stats() -> Result<(), Box> { let mut wtr = csv::Writer::from_path("armorstats.csv")?; - wtr.write_record(&[ + wtr.write_record([ "Path", "Kind", "Name", @@ -74,7 +74,7 @@ fn armor_stats() -> Result<(), Box> { let crit_power = armor.stats(msm).crit_power.unwrap_or(0.0).to_string(); let stealth = armor.stats(msm).stealth.unwrap_or(0.0).to_string(); - wtr.write_record(&[ + wtr.write_record([ item.item_definition_id() .itemdef_id() .expect("All items from asset glob should be simple items"), @@ -100,7 +100,7 @@ fn armor_stats() -> Result<(), Box> { fn weapon_stats() -> Result<(), Box> { let mut wtr = csv::Writer::from_path("weaponstats.csv")?; - wtr.write_record(&[ + wtr.write_record([ "Path", "Kind", "Name", @@ -135,7 +135,7 @@ fn weapon_stats() -> Result<(), Box> { let kind = get_tool_kind(&tool.kind); let hands = get_tool_hands(tool); - wtr.write_record(&[ + wtr.write_record([ item.item_definition_id() .itemdef_id() .expect("All items from asset glob should be simple items"), @@ -207,12 +207,12 @@ fn get_armor_kind(kind: &ArmorKind) -> String { fn all_items() -> Result<(), Box> { let mut wtr = csv::Writer::from_path("items.csv")?; - wtr.write_record(&["Path", "Name"])?; + wtr.write_record(["Path", "Name"])?; for item in Item::new_from_asset_glob("common.items.*").expect("Failed to iterate over item folders!") { - wtr.write_record(&[ + wtr.write_record([ item.item_definition_id() .itemdef_id() .expect("All items in asset glob should be simple items"), @@ -226,7 +226,7 @@ fn all_items() -> Result<(), Box> { fn loot_table(loot_table: &str) -> Result<(), Box> { let mut wtr = csv::Writer::from_path("loot_table.csv")?; - wtr.write_record(&[ + wtr.write_record([ "Relative Chance", "Kind", "Item", @@ -256,8 +256,8 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { }; match item { - LootSpec::Item(item) => wtr.write_record(&[&chance, "Item", item, "", ""])?, - LootSpec::ItemQuantity(item, lower, upper) => wtr.write_record(&[ + LootSpec::Item(item) => wtr.write_record([&chance, "Item", item, "", ""])?, + LootSpec::ItemQuantity(item, lower, upper) => wtr.write_record([ &chance, "Item", item, @@ -265,14 +265,14 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { &upper.to_string(), ])?, LootSpec::LootTable(table) => { - wtr.write_record(&[&chance, "LootTable", table, "", ""])? + wtr.write_record([&chance, "LootTable", table, "", ""])? }, - LootSpec::Nothing => wtr.write_record(&[&chance, "Nothing", "", ""])?, + LootSpec::Nothing => wtr.write_record([&chance, "Nothing", "", ""])?, LootSpec::ModularWeapon { tool, material, hands, - } => wtr.write_record(&[ + } => wtr.write_record([ &chance, "Modular Weapon", &get_tool_kind(tool), @@ -283,7 +283,7 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { tool, material, hands, - } => wtr.write_record(&[ + } => wtr.write_record([ &chance, "Modular Weapon Primary Component", &get_tool_kind(tool), @@ -299,7 +299,7 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { fn entity_drops(entity_config: &str) -> Result<(), Box> { let mut wtr = csv::Writer::from_path("drop_table.csv")?; - wtr.write_record(&[ + wtr.write_record([ "Entity Name", "Entity Path", "Percent Chance", @@ -314,7 +314,7 @@ fn entity_drops(entity_config: &str) -> Result<(), Box> { let entity_config = EntityConfig::load_expect(asset_path).read(); let entity_info = EntityInfo::at(Vec3::new(0.0, 0.0, 0.0)) .with_asset_expect(asset_path, &mut rand::thread_rng()); - let name = entity_info.name.unwrap_or_else(|| "".to_string()); + let name = entity_info.name.unwrap_or_default(); // Create initial entry in drop table let entry: (f32, LootSpec) = (1.0, entity_config.loot.clone()); diff --git a/common/src/comp/inventory/item/modular.rs b/common/src/comp/inventory/item/modular.rs index 9bb079f7b7..bfdfaeb5de 100644 --- a/common/src/comp/inventory/item/modular.rs +++ b/common/src/comp/inventory/item/modular.rs @@ -342,9 +342,9 @@ lazy_static! { } else { return; }; - let entry = component_pool + let entry: &mut Vec<_> = component_pool .entry((*toolkind, String::from(material))) - .or_insert(Vec::new()); + .or_default(); entry.push((component, hand_restriction)); }, ); @@ -371,7 +371,7 @@ lazy_static! { }, ) = comp_def.kind { - let entry = component_pool.entry(toolkind).or_insert(Vec::new()); + let entry: &mut Vec<_> = component_pool.entry(toolkind).or_default(); entry.push((Arc::clone(&comp_def), hand_restriction)); } }); diff --git a/common/src/comp/inventory/trade_pricing.rs b/common/src/comp/inventory/trade_pricing.rs index 44da73fe28..39cb10aee5 100644 --- a/common/src/comp/inventory/trade_pricing.rs +++ b/common/src/comp/inventory/trade_pricing.rs @@ -279,7 +279,7 @@ lazy_static! { .for_each(|(ComponentKey { toolkind, material, .. }, recipe)| { let component = recipe.itemdef_output(); let hand_restriction = None; // once there exists a hand restriction add the logic here - for a slight price correction - let entry = component_pool.entry((*toolkind, String::from(material))).or_insert(Vec::new()); + let entry: &mut Vec<_> = component_pool.entry((*toolkind, String::from(material))).or_default(); entry.push((component, hand_restriction)); }); @@ -306,7 +306,7 @@ lazy_static! { ) = asset_path.kind { let component = ItemDefinitionIdOwned::Simple(asset_path.id().into()); - let entry = component_pool.entry((toolkind, String::new())).or_insert(Vec::new()); + let entry: &mut Vec<_> = component_pool.entry((toolkind, String::new())).or_default(); entry.push((component, hand_restriction)); }}); @@ -790,7 +790,7 @@ impl TradePricing { { secondaries .entry(toolkind) - .or_insert(Vec::new()) + .or_default() .push(ItemDefinitionIdOwned::Simple(asset_path.id().into())); } ordered_recipes.push(RememberedRecipe { @@ -822,7 +822,7 @@ impl TradePricing { for (key, recipe) in comp_book.iter() { primaries .entry(key.toolkind) - .or_insert(Vec::new()) + .or_default() .push(recipe.itemdef_output()); ordered_recipes.push(RememberedRecipe { output: recipe.itemdef_output(), diff --git a/common/src/comp/skillset/mod.rs b/common/src/comp/skillset/mod.rs index 4c9813d6ab..4af5d8ff9f 100644 --- a/common/src/comp/skillset/mod.rs +++ b/common/src/comp/skillset/mod.rs @@ -478,7 +478,7 @@ impl SkillSet { C: BorrowMut, { if let Some(skill_group_kind) = skill.skill_group_kind() { - let this = (&*this_).borrow(); + let this = (*this_).borrow(); let next_level = this.next_skill_level(skill); let prerequisites_met = this.prerequisites_met(skill); // Check that skill is not yet at max level diff --git a/common/src/lib.rs b/common/src/lib.rs index 97625ca04a..d9675bb3a3 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -12,7 +12,6 @@ type_alias_impl_trait, extend_one, arbitrary_enum_discriminant, - generic_associated_types, arbitrary_self_types )] #![feature(hash_drain_filter)] diff --git a/common/src/path.rs b/common/src/path.rs index c6c266d95c..439875276b 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -521,7 +521,7 @@ where if is_walkable(&test_pos) { return Some(test_pos); } - z_incr = -z_incr + if z_incr <= 0 { 1 } else { 0 }; + z_incr = -z_incr + i32::from(z_incr <= 0); } None }; diff --git a/common/src/terrain/map.rs b/common/src/terrain/map.rs index e2e1b2f371..3a75c85727 100644 --- a/common/src/terrain/map.rs +++ b/common/src/terrain/map.rs @@ -470,7 +470,7 @@ impl<'a> MapConfig<'a> { light_direction.y, 0.0, // we currently ignore light_direction.z. ); - let light_shadow_dir = if light_direction.x >= 0.0 { 0 } else { 1 }; + let light_shadow_dir = usize::from(light_direction.x < 0.0); let horizon_map = horizons.map(|horizons| &horizons[light_shadow_dir]); let light = light_direction.normalized(); let /*mut */quads = [[0u32; QUADRANTS]; QUADRANTS]; diff --git a/common/src/volumes/chunk.rs b/common/src/volumes/chunk.rs index 3bcacf65c8..965c21bda0 100644 --- a/common/src/volumes/chunk.rs +++ b/common/src/volumes/chunk.rs @@ -123,7 +123,7 @@ impl Chunk { { // First, construct a HashMap with max capacity equal to GROUP_COUNT (since each // filled group can have at most one slot). - let mut map = HashMap::with_capacity(Self::GROUP_COUNT_TOTAL as usize); + let mut map: HashMap<_, Vec<_>> = HashMap::with_capacity(Self::GROUP_COUNT_TOTAL as usize); let vox = &self.vox; let default = &self.default; self.indices @@ -139,11 +139,11 @@ impl Chunk { if group.all(|block| block == first) { // All blocks in the group were the same, so add our position to this entry // in the HashMap. - map.entry(first).or_insert(vec![]).push(grp_idx); + map.entry(first).or_default().push(grp_idx); } } else { // This slot is empty (i.e. has the default value). - map.entry(default).or_insert(vec![]).push(grp_idx); + map.entry(default).or_default().push(grp_idx); } }); // Now, find the block with max frequency in the HashMap and make that our new diff --git a/common/systems/src/lib.rs b/common/systems/src/lib.rs index 05fab14477..a0e18fcf5f 100644 --- a/common/systems/src/lib.rs +++ b/common/systems/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(let_else, btree_drain_filter)] +#![feature(btree_drain_filter)] #![allow(clippy::option_map_unit_fn)] mod aura; diff --git a/rust-toolchain b/rust-toolchain index 62193b6c62..0f65080bf5 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-09-08 +nightly-2022-09-23 diff --git a/server/src/lib.rs b/server/src/lib.rs index 072b644b18..e40fb7778a 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -5,7 +5,6 @@ box_patterns, drain_filter, let_chains, - let_else, never_type, option_zip, unwrap_infallible diff --git a/server/src/rtsim/entity.rs b/server/src/rtsim/entity.rs index 503ad5d58f..2046e14dfc 100644 --- a/server/src/rtsim/entity.rs +++ b/server/src/rtsim/entity.rs @@ -26,7 +26,7 @@ pub struct Entity { pub brain: Brain, } -#[derive(Clone, Copy, strum::EnumIter, PartialEq)] +#[derive(Clone, Copy, strum::EnumIter, PartialEq, Eq)] pub enum RtSimEntityKind { Wanderer, Cultist, diff --git a/server/src/sys/agent/behavior_tree/interaction.rs b/server/src/sys/agent/behavior_tree/interaction.rs index 08b99805a3..706a31fa79 100644 --- a/server/src/sys/agent/behavior_tree/interaction.rs +++ b/server/src/sys/agent/behavior_tree/interaction.rs @@ -488,11 +488,7 @@ pub fn handle_inbox_update_pending_trade(bdata: &mut BehaviorData) -> bool { if let Some(AgentEvent::UpdatePendingTrade(boxval)) = agent.inbox.pop_front() { let (tradeid, pending, prices, inventories) = *boxval; if agent.behavior.is(BehaviorState::TRADING) { - let who: usize = if agent.behavior.is(BehaviorState::TRADING_ISSUER) { - 0 - } else { - 1 - }; + let who = usize::from(!agent.behavior.is(BehaviorState::TRADING_ISSUER)); let balance0: f32 = prices.balance(&pending.offers, &inventories, 1 - who, true); let balance1: f32 = prices.balance(&pending.offers, &inventories, who, false); if balance0 >= balance1 { diff --git a/server/src/sys/sentinel.rs b/server/src/sys/sentinel.rs index b9537d86de..a73cbb96b5 100644 --- a/server/src/sys/sentinel.rs +++ b/server/src/sys/sentinel.rs @@ -293,10 +293,7 @@ impl Default for DeletedEntities { impl DeletedEntities { pub fn record_deleted_entity(&mut self, uid: Uid, region_key: Vec2) { - self.map - .entry(region_key) - .or_insert(Vec::new()) - .push(uid.into()); + self.map.entry(region_key).or_default().push(uid.into()); } pub fn take_deleted_in_region(&mut self, key: Vec2) -> Vec { diff --git a/voxygen/anim/src/lib.rs b/voxygen/anim/src/lib.rs index bd736fa20b..67a42181ab 100644 --- a/voxygen/anim/src/lib.rs +++ b/voxygen/anim/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(generic_associated_types)] #![allow(incomplete_features)] #![allow(clippy::single_match)] #[cfg(all(feature = "be-dyn-lib", feature = "use-dyn-lib"))] diff --git a/voxygen/src/cmd.rs b/voxygen/src/cmd.rs index 46d90ceb50..347364a841 100644 --- a/voxygen/src/cmd.rs +++ b/voxygen/src/cmd.rs @@ -340,7 +340,7 @@ pub fn complete(line: &str, client: &Client, cmd_prefix: char) -> Vec { let line = line.strip_prefix(cmd_prefix).unwrap_or(line); let mut iter = line.split_whitespace(); let cmd = iter.next().unwrap_or(""); - let i = iter.count() + if word.is_empty() { 1 } else { 0 }; + let i = iter.count() + usize::from(word.is_empty()); if i == 0 { // Completing chat command name. This is the start of the line so the prefix // will be part of it diff --git a/voxygen/src/hud/overhead.rs b/voxygen/src/hud/overhead.rs index 4a311428c3..03c6e60335 100644 --- a/voxygen/src/hud/overhead.rs +++ b/voxygen/src/hud/overhead.rs @@ -164,15 +164,11 @@ impl<'a> Ingameable for Overhead<'a> { 0 } + if info.health.map_or(false, should_show_healthbar) { - 5 + if info.energy.is_some() { 1 } else { 0 } - } else { - 0 - } - + if info.health.map_or(false, decayed_health_displayed) { - 1 + 5 + usize::from(info.energy.is_some()) } else { 0 } + + usize::from(info.health.map_or(false, decayed_health_displayed)) + (!self.interaction_options.is_empty()) as usize * 2 }) + if self.bubble.is_some() { 13 } else { 0 } } diff --git a/voxygen/src/profile.rs b/voxygen/src/profile.rs index 3cd2c54676..21865fcc86 100644 --- a/voxygen/src/profile.rs +++ b/voxygen/src/profile.rs @@ -150,7 +150,7 @@ impl Profile { match character_id { Some(character_id) => self.servers .entry(server.to_string()) - .or_insert(ServerProfile::default()) + .or_default() // Get or update the CharacterProfile. .characters .entry(character_id) @@ -191,7 +191,7 @@ impl Profile { ) { self.servers .entry(server.to_string()) - .or_insert(ServerProfile::default()) + .or_default() .selected_character = selected_character; } @@ -226,7 +226,7 @@ impl Profile { ) { self.servers .entry(server.to_string()) - .or_insert(ServerProfile::default()) + .or_default() .spectate_position = spectate_position; } diff --git a/voxygen/src/render/pipelines/fluid.rs b/voxygen/src/render/pipelines/fluid.rs index de9c70c177..a5c37fe961 100644 --- a/voxygen/src/render/pipelines/fluid.rs +++ b/voxygen/src/render/pipelines/fluid.rs @@ -17,7 +17,7 @@ impl Vertex { .enumerate() .find(|(_i, e)| **e != 0.0) .unwrap_or((0, &1.0)); - let norm_bits = ((norm_axis << 1) | if *norm_dir > 0.0 { 1 } else { 0 }) as u32; + let norm_bits = ((norm_axis << 1) | usize::from(*norm_dir > 0.0)) as u32; const EXTRA_NEG_Z: f32 = 65536.0; diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index 35febbe5ef..62d5f89d88 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -18,6 +18,7 @@ pub struct Vertex { impl Vertex { #[allow(clippy::collapsible_else_if)] pub fn new(pos: Vec3, norm: Vec3) -> Self { + #[allow(clippy::bool_to_int_with_if)] let norm_bits = if norm.x != 0.0 { if norm.x < 0.0 { 0 } else { 1 } } else if norm.y != 0.0 { diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 3c0085dd7c..b6eacd92a1 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -44,6 +44,7 @@ impl Vertex { pub fn new(atlas_pos: Vec2, pos: Vec3, norm: Vec3) -> Self { const VERT_EXTRA_NEG_Z: i32 = 128; // NOTE: change if number of bits changes below, also we might not need this if meshing always produces positives values for sprites (I have no idea) + #[allow(clippy::bool_to_int_with_if)] let norm_bits = if norm.x != 0.0 { if norm.x < 0.0 { 0 } else { 1 } } else if norm.y != 0.0 { diff --git a/voxygen/src/render/pipelines/terrain.rs b/voxygen/src/render/pipelines/terrain.rs index 8a6e4ad16e..08fa8be8ef 100644 --- a/voxygen/src/render/pipelines/terrain.rs +++ b/voxygen/src/render/pipelines/terrain.rs @@ -15,6 +15,7 @@ impl Vertex { pub fn new(atlas_pos: Vec2, pos: Vec3, norm: Vec3, meta: bool) -> Self { const EXTRA_NEG_Z: f32 = 32768.0; + #[allow(clippy::bool_to_int_with_if)] let norm_bits = if norm.x != 0.0 { if norm.x < 0.0 { 0 } else { 1 } } else if norm.y != 0.0 { @@ -28,18 +29,14 @@ impl Vertex { pos_norm: ((pos.x as u32) & 0x003F) << 0 | ((pos.y as u32) & 0x003F) << 6 | (((pos + EXTRA_NEG_Z).z.max(0.0).min((1 << 16) as f32) as u32) & 0xFFFF) << 12 - | if meta { 1 } else { 0 } << 28 + | u32::from(meta) << 28 | (norm_bits & 0x7) << 29, atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) << 0 | ((atlas_pos.y as u32) & 0xFFFF) << 16, } } pub fn new_figure(atlas_pos: Vec2, pos: Vec3, norm: Vec3, bone_idx: u8) -> Self { - let norm_bits = if norm.x.min(norm.y).min(norm.z) < 0.0 { - 0 - } else { - 1 - }; + let norm_bits = u32::from(norm.x.min(norm.y).min(norm.z) >= 0.0); let axis_bits = if norm.x != 0.0 { 0 } else if norm.y != 0.0 { diff --git a/voxygen/src/scene/lod.rs b/voxygen/src/scene/lod.rs index 83ace9d18e..f92041928e 100644 --- a/voxygen/src/scene/lod.rs +++ b/voxygen/src/scene/lod.rs @@ -234,11 +234,9 @@ fn create_lod_terrain_mesh(detail: u32) -> Mesh { Vertex::new(Vec2::new(x + 1, y + 1).map(transform)), Vertex::new(Vec2::new(x, y + 1).map(transform)), ) - .rotated_by(if (x > detail as i32 / 2) ^ (y > detail as i32 / 2) { - 0 - } else { - 1 - }) + .rotated_by(usize::from( + !((x > detail as i32 / 2) ^ (y > detail as i32 / 2)), + )) }) .collect() } diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 9e6366a62f..159dea318f 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -1079,11 +1079,7 @@ impl ParticleMgr { } => { let num_particles = aura.radius.powi(2) * dt / 250.0; let num_particles = num_particles.floor() as usize - + if rng.gen_bool(f64::from(num_particles % 1.0)) { - 1 - } else { - 0 - }; + + usize::from(rng.gen_bool(f64::from(num_particles % 1.0))); self.particles .resize_with(self.particles.len() + num_particles, || { let rand_pos = { diff --git a/world/examples/chunk_compression_benchmarks.rs b/world/examples/chunk_compression_benchmarks.rs index 7d3b4333e7..f4ff72c75b 100644 --- a/world/examples/chunk_compression_benchmarks.rs +++ b/world/examples/chunk_compression_benchmarks.rs @@ -48,7 +48,7 @@ fn unlz4_with_dictionary(data: &[u8], dictionary: &[u8]) -> Option> { r.into_read_with_dictionary(dictionary) .read_to_end(&mut uncompressed) .ok()?; - bincode::deserialize(&*uncompressed).ok() + bincode::deserialize(&uncompressed).ok() }) } @@ -201,7 +201,7 @@ impl VoxelImageEncoding for PngEncoding { FilterType::Up, ); png.write_image( - &*ws.as_raw(), + ws.as_raw(), ws.width(), ws.height(), image::ColorType::Rgba8, @@ -300,7 +300,7 @@ impl VoxelImageEncoding for MixedEncoding { CompressionType::Rle, FilterType::Up, ); - png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) + png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) .ok()?; indices[i] = buf.len(); Some(()) @@ -407,7 +407,7 @@ impl VoxelImageEncoding for MixedEncodingSparseSprites { FilterType::Up, ); png.write_image( - &*ws.0.as_raw(), + ws.0.as_raw(), ws.0.width(), ws.0.height(), image::ColorType::L8, @@ -471,14 +471,14 @@ impl VoxelImageEncoding for MixedEncodingDenseSprites { CompressionType::Fast, FilterType::Up, ); - png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) + png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) .ok()?; indices[i] = buf.len(); Some(()) }; f(&ws.0, 0)?; let mut g = |x: &[u8], i| { - buf.extend_from_slice(&*CompressedData::compress(&x, 4).data); + buf.extend_from_slice(&CompressedData::compress(&x, 4).data); indices[i] = buf.len(); }; @@ -533,7 +533,7 @@ lazy_static::lazy_static! { static ref PALETTE_RTREE: HashMap> = { let ron_bytes = include_bytes!("palettes.ron"); let palettes: HashMap>> = - ron::de::from_bytes(&*ron_bytes).expect("palette should parse"); + ron::de::from_bytes(ron_bytes).expect("palette should parse"); palettes .into_iter() .map(|(k, v)| { @@ -549,7 +549,7 @@ lazy_static::lazy_static! { pub static ref PALETTE_KDTREE: HashMap> = { let ron_bytes = include_bytes!("palettes.ron"); let palettes: HashMap>> = - ron::de::from_bytes(&*ron_bytes).expect("palette should parse"); + ron::de::from_bytes(ron_bytes).expect("palette should parse"); palettes .into_iter() .map(|(k, v)| { @@ -637,7 +637,7 @@ impl<'a, NN: NearestNeighbor, const N: u32> VoxelImageEncoding for PaletteEncodi CompressionType::Rle, FilterType::Up, ); - png.write_image(&*x.as_raw(), x.width(), x.height(), image::ColorType::L8) + png.write_image(x.as_raw(), x.width(), x.height(), image::ColorType::L8) .ok()?; indices[i] = buf.len(); Some(()) @@ -921,8 +921,8 @@ fn main() { histogram_to_dictionary(&histogram2, &mut dictionary2); } } - let lz4_dyna = lz4_with_dictionary(&*ser_dyna, &[]); - let deflate_dyna = do_deflate_flate2::<5>(&*ser_dyna); + let lz4_dyna = lz4_with_dictionary(&ser_dyna, &[]); + let deflate_dyna = do_deflate_flate2::<5>(&ser_dyna); let deflate_channeled_dyna = do_deflate_flate2::<5>( &bincode::serialize(&channelize_dyna(&dyna)).unwrap(), ); @@ -936,7 +936,7 @@ fn main() { ), ]); if HISTOGRAMS { - let lz4_dict_dyna = lz4_with_dictionary(&*ser_dyna, &dictionary2); + let lz4_dict_dyna = lz4_with_dictionary(&ser_dyna, &dictionary2); sizes.push(("lz4_dict_dyna", lz4_dict_dyna.len() as f32 / n as f32)); } } @@ -954,7 +954,7 @@ fn main() { spiralpos.x, spiralpos.y )) .unwrap(); - f.write_all(&*jpegchonkgrid).unwrap(); + f.write_all(&jpegchonkgrid).unwrap(); } let jpegchonktall_pre = Instant::now(); @@ -1199,7 +1199,7 @@ fn main() { .unwrap(); let jpeg_volgrid = image_terrain_volgrid(&JpegEncoding, GridLtrPacking, &volgrid).unwrap(); - f.write_all(&*jpeg_volgrid).unwrap(); + f.write_all(&jpeg_volgrid).unwrap(); let mixedgrid_pre = Instant::now(); let (mixed_volgrid, indices) = diff --git a/world/examples/dungeon_voxel_export.rs b/world/examples/dungeon_voxel_export.rs index 3bf0f597b0..f4eade09ad 100644 --- a/world/examples/dungeon_voxel_export.rs +++ b/world/examples/dungeon_voxel_export.rs @@ -179,8 +179,8 @@ impl ExportVol { for (index, (model_pos, _)) in self.models.iter().enumerate() { // Transform node - let pos = model_pos - .map(|p| p * Self::CHUNK_SIZE + Self::CHUNK_SIZE / 2 + if p < 0 { 0 } else { 1 }); + let pos = + model_pos.map(|p| p * Self::CHUNK_SIZE + Self::CHUNK_SIZE / 2 + i32::from(p >= 0)); let pos = pos - Vec3::new(self.width / 2, self.width / 2, 0); let transform_node_id = index as i32 * 2 + 2; let shape_node_id = index as i32 * 2 + 3; diff --git a/world/examples/heightmap_visualization.rs b/world/examples/heightmap_visualization.rs index a192d9c192..f457bc7d0f 100644 --- a/world/examples/heightmap_visualization.rs +++ b/world/examples/heightmap_visualization.rs @@ -84,14 +84,14 @@ fn image_from_function [u8; 3]>( let png = PngEncoder::new_with_quality(&mut heightmap_png, CompressionType::Best, FilterType::Paeth); png.write_image( - &*heightmap.as_raw(), + heightmap.as_raw(), heightmap.width(), heightmap.height(), image::ColorType::Rgb8, ) .unwrap(); let mut f = File::create(name).unwrap(); - f.write_all(&*heightmap_png).unwrap(); + f.write_all(&heightmap_png).unwrap(); } fn image_with_autorange [u8; 3], G: FnMut(u32, u32) -> f32>( diff --git a/world/examples/world_block_statistics.rs b/world/examples/world_block_statistics.rs index 9489bc6c9d..41e9ae4fa4 100644 --- a/world/examples/world_block_statistics.rs +++ b/world/examples/world_block_statistics.rs @@ -274,7 +274,7 @@ fn main() -> Result<(), Box> { }, Some(("palette", matches)) => { let conn = - Connection::open(&matches.value_of("database").expect("database is required"))?; + Connection::open(matches.value_of("database").expect("database is required"))?; palette(conn)?; }, _ => { diff --git a/world/src/lib.rs b/world/src/lib.rs index 4bc34ff0ed..c51c3a51ba 100644 --- a/world/src/lib.rs +++ b/world/src/lib.rs @@ -7,7 +7,7 @@ )] #![allow(clippy::branches_sharing_code)] // TODO: evaluate #![deny(clippy::clone_on_ref_ptr)] -#![feature(option_zip, arbitrary_enum_discriminant, let_else)] +#![feature(option_zip, arbitrary_enum_discriminant)] mod all; mod block; diff --git a/world/src/site/economy/context.rs b/world/src/site/economy/context.rs index 0614c0f932..2b134449c2 100644 --- a/world/src/site/economy/context.rs +++ b/world/src/site/economy/context.rs @@ -237,12 +237,7 @@ fn tick(index: &mut Index, dt: f32, _env: &mut Environment) { // distribute orders (travelling merchants) for (_id, site) in index.sites.iter_mut() { for (i, mut v) in site.economy.orders.drain() { - index - .trade - .orders - .entry(i) - .or_insert(Vec::new()) - .append(&mut v); + index.trade.orders.entry(i).or_default().append(&mut v); } } // trade at sites diff --git a/world/src/site/settlement/building/archetype/keep.rs b/world/src/site/settlement/building/archetype/keep.rs index 065d34dd53..530dd288fe 100644 --- a/world/src/site/settlement/building/archetype/keep.rs +++ b/world/src/site/settlement/building/archetype/keep.rs @@ -192,12 +192,7 @@ impl Archetype for Keep { }; let ridge_x = (center_offset.map(|e| e.abs()).reduce_min() + 2) % 8; - let width = locus - + if ridge_x < 4 && attr.ridged && !attr.rounded { - 1 - } else { - 0 - }; + let width = locus + i32::from(ridge_x < 4 && attr.ridged && !attr.rounded); let rampart_width = 2 + width; let storey_height = 9; let roof_height = attr.storeys * storey_height; diff --git a/world/src/site2/plot/dungeon.rs b/world/src/site2/plot/dungeon.rs index 2d448f0910..6f8f8911b3 100644 --- a/world/src/site2/plot/dungeon.rs +++ b/world/src/site2/plot/dungeon.rs @@ -222,7 +222,7 @@ impl Room { .map(|e| e.rem_euclid(pillar_space) == 0) .reduce_and() }); - let enemy_spawn_tile = enemy_spawn_tile + if enemy_tile_is_pillar { 1 } else { 0 }; + let enemy_spawn_tile = enemy_spawn_tile + i32::from(enemy_tile_is_pillar); // Toss mobs in the center of the room if tile_pos == enemy_spawn_tile && wpos2d == tile_wcenter.xy() { @@ -281,7 +281,7 @@ impl Room { .map(|e| e.rem_euclid(pillar_space) == 0) .reduce_and() }); - let miniboss_spawn_tile = miniboss_spawn_tile + if miniboss_tile_is_pillar { 1 } else { 0 }; + let miniboss_spawn_tile = miniboss_spawn_tile + i32::from(miniboss_tile_is_pillar); if tile_pos == miniboss_spawn_tile && tile_wcenter.xy() == wpos2d { let entities = match self.difficulty { @@ -314,7 +314,7 @@ impl Room { .map(|e| e.rem_euclid(pillar_space) == 0) .reduce_and() }); - let boss_spawn_tile = boss_spawn_tile + if boss_tile_is_pillar { 1 } else { 0 }; + let boss_spawn_tile = boss_spawn_tile + i32::from(boss_tile_is_pillar); if tile_pos == boss_spawn_tile && wpos2d == tile_wcenter.xy() { let entities = match self.difficulty { diff --git a/world/src/site2/plot/house.rs b/world/src/site2/plot/house.rs index 6bf1a3a33f..f6e99b722b 100644 --- a/world/src/site2/plot/house.rs +++ b/world/src/site2/plot/house.rs @@ -42,6 +42,7 @@ impl House { min: site.tile_wpos(tile_aabr.min), max: site.tile_wpos(tile_aabr.max), }; + #[allow(clippy::bool_to_int_with_if)] let front = if door_dir.y < 0 { 2 } else if door_dir.x < 0 {