diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 537ef56aea..96ca76c55b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,7 @@ variables: # https://docs.gitlab.com/ee/ci/yaml/#shallow-cloning GIT_DEPTH: 3 GIT_CLEAN_FLAGS: -f - CACHE_IMAGE_TAG: a4f7c998 + CACHE_IMAGE_TAG: dd8d78be default: # https://docs.gitlab.com/ee/ci/pipelines/settings.html#auto-cancel-pending-pipelines diff --git a/common/ecs/src/system.rs b/common/ecs/src/system.rs index 73e9ce329a..3ab41663cf 100644 --- a/common/ecs/src/system.rs +++ b/common/ecs/src/system.rs @@ -170,13 +170,12 @@ pub fn gen_stats( let mut result = HashMap::new(); let mut all = timelines .iter() - .map(|(s, t)| { + .flat_map(|(s, t)| { let mut stat = CpuTimeStats::default(); stat.measures.push((0, 0.0)); result.insert(s.clone(), stat); t.measures.iter().map(|e| &e.0) }) - .flatten() .collect::>(); all.sort(); diff --git a/common/net/src/sync/interpolation.rs b/common/net/src/sync/interpolation.rs index 00650abd37..d183573d48 100644 --- a/common/net/src/sync/interpolation.rs +++ b/common/net/src/sync/interpolation.rs @@ -88,9 +88,8 @@ impl InterpolatableComponent for Pos { } let (t0prime, m0) = vel.buf[(i + vel.buf.len() - 1) % vel.buf.len()]; let (t1prime, m1) = vel.buf[i % vel.buf.len()]; - let mut out; let t = (t2 - t0) / (t1 - t0); - if ENABLE_POSITION_HERMITE + let mut out = if ENABLE_POSITION_HERMITE && ((t0 - t0prime).abs() < f64::EPSILON && (t1 - t1prime).abs() < f64::EPSILON) { let h00 = |t: f64| (2.0 * t.powf(3.0) - 3.0 * t.powf(2.0) + 1.0) as f32; @@ -98,7 +97,7 @@ impl InterpolatableComponent for Pos { let h01 = |t: f64| (-2.0 * t.powf(3.0) + 3.0 * t.powf(2.0)) as f32; let h11 = |t: f64| (t.powf(3.0) - t.powf(2.0)) as f32; let dt = (t1 - t0) as f32; - out = h00(t) * p0.0 + h10(t) * dt * m0.0 + h01(t) * p1.0 + h11(t) * dt * m1.0; + h00(t) * p0.0 + h10(t) * dt * m0.0 + h01(t) * p1.0 + h11(t) * dt * m1.0 } else { if ENABLE_POSITION_HERMITE { warn!( @@ -106,8 +105,8 @@ impl InterpolatableComponent for Pos { interp_data, vel ); } - out = Lerp::lerp_unclamped(p0.0, p1.0, t as f32); - } + Lerp::lerp_unclamped(p0.0, p1.0, t as f32) + }; if out.map(|x| x.is_nan()).reduce_or() { warn!("interpolation output is nan: {}, {}, {:?}", t2, t, buf); diff --git a/common/net/src/sync/packet.rs b/common/net/src/sync/packet.rs index 87bfe0a0c3..f65b882366 100644 --- a/common/net/src/sync/packet.rs +++ b/common/net/src/sync/packet.rs @@ -52,6 +52,7 @@ pub trait InterpolatableComponent: Component { fn new_data(x: Self) -> Self::InterpData; fn update_component(&self, data: &mut Self::InterpData, time: f64, force_update: bool); + #[must_use] fn interpolate(self, data: &Self::InterpData, time: f64, read_data: &Self::ReadData) -> Self; } @@ -167,6 +168,7 @@ impl CompSyncPackage

{ .push((uid.into(), CompUpdateKind::Removed(PhantomData::.into()))); } + #[must_use] pub fn with_component<'a, C: Component + Clone + Send + Sync>( mut self, uids: &ReadStorage<'a, Uid>, diff --git a/common/src/combat.rs b/common/src/combat.rs index 25dcdf7d55..ba4493e80b 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -102,22 +102,26 @@ impl Default for Attack { #[cfg(not(target_arch = "wasm32"))] impl Attack { + #[must_use] pub fn with_damage(mut self, damage: AttackDamage) -> Self { self.damages.push(damage); self } + #[must_use] pub fn with_effect(mut self, effect: AttackEffect) -> Self { self.effects.push(effect); self } + #[must_use] pub fn with_crit(mut self, crit_chance: f32, crit_multiplier: f32) -> Self { self.crit_chance = crit_chance; self.crit_multiplier = crit_multiplier; self } + #[must_use] pub fn with_combo_increment(self) -> Self { self.with_effect( AttackEffect::new(None, CombatEffect::Combo(1)) @@ -544,6 +548,7 @@ impl AttackDamage { } } + #[must_use] pub fn with_effect(mut self, effect: CombatEffect) -> Self { self.effects.push(effect); self @@ -568,6 +573,7 @@ impl AttackEffect { } } + #[must_use] pub fn with_requirement(mut self, requirement: CombatRequirement) -> Self { self.requirements.push(requirement); self @@ -806,6 +812,7 @@ impl Knockback { } } + #[must_use] pub fn modify_strength(mut self, power: f32) -> Self { self.strength *= power; self diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index ee40f6b58e..ae39fc25f1 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -673,6 +673,7 @@ impl CharacterAbility { } } + #[must_use] pub fn adjusted_by_stats(mut self, stats: Stats) -> Self { use CharacterAbility::*; match self { diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 89255e99a9..a535919411 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -126,6 +126,7 @@ impl From for Behavior { impl Behavior { /// Builder function /// Set capabilities if Option is Some + #[must_use] pub fn maybe_with_capabilities( mut self, maybe_capabilities: Option, @@ -138,6 +139,7 @@ impl Behavior { /// Builder function /// Set trade_site if Option is Some + #[must_use] pub fn with_trade_site(mut self, trade_site: Option) -> Self { self.trade_site = trade_site; self @@ -323,6 +325,7 @@ impl Sound { } } + #[must_use] pub fn with_new_vol(mut self, new_vol: f32) -> Self { self.vol = new_vol; @@ -480,16 +483,19 @@ impl Agent { } } + #[must_use] pub fn with_patrol_origin(mut self, origin: Vec3) -> Self { self.patrol_origin = Some(origin); self } + #[must_use] pub fn with_behavior(mut self, behavior: Behavior) -> Self { self.behavior = behavior; self } + #[must_use] pub fn with_no_flee_if(mut self, condition: bool) -> Self { if condition { self.psyche.flee_health = 0.0; @@ -498,6 +504,7 @@ impl Agent { } // FIXME: Only one of *three* things in this method sets a location. + #[must_use] pub fn with_destination(mut self, pos: Vec3) -> Self { self.psyche.flee_health = 0.0; self.rtsim_controller = RtSimController::with_destination(pos); @@ -506,6 +513,7 @@ impl Agent { } #[allow(clippy::type_complexity)] + #[must_use] pub fn with_position_pid_controller( mut self, pid: PidController, Vec3) -> f32, 16>, @@ -514,6 +522,7 @@ impl Agent { self } + #[must_use] pub fn with_aggro_no_warn(mut self) -> Self { self.psyche.aggro_dist = None; self diff --git a/common/src/comp/fluid_dynamics.rs b/common/src/comp/fluid_dynamics.rs index 1607cb5f2c..1f6e2960ba 100644 --- a/common/src/comp/fluid_dynamics.rs +++ b/common/src/comp/fluid_dynamics.rs @@ -20,7 +20,8 @@ impl LiquidKind { /// precedence? (should be a rare edge case, since checkerboard patterns of /// water and lava shouldn't show up in worldgen) #[inline] - pub fn merge(self, other: LiquidKind) -> LiquidKind { + #[must_use] + pub fn merge(self, other: Self) -> Self { use LiquidKind::{Lava, Water}; match (self, other) { (Water, Water) => Water, diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index 51b17796b9..a808d85dd1 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -675,6 +675,7 @@ impl Item { } /// Duplicates an item, creating an exact copy but with a new item ID + #[must_use] pub fn duplicate(&self, ability_map: &AbilityMap, msm: &MaterialStatManifest) -> Self { let mut new_item = Item::new_from_item_def( Arc::clone(&self.item_def), diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index fcb54deb7a..e7d64afe5d 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -105,7 +105,8 @@ impl Stats { } } - pub fn clamp_speed(mut self) -> Stats { + #[must_use] + pub fn clamp_speed(mut self) -> Self { // if a tool has 0.0 speed, that panics due to being infinite duration, so // enforce speed >= 0.1 on the final product (but not the intermediates) self.speed = self.speed.max(0.1); @@ -345,6 +346,7 @@ pub struct AbilitySet { } impl AbilitySet { + #[must_use] pub fn modified_by_tool( self, tool: &Tool, diff --git a/common/src/comp/ori.rs b/common/src/comp/ori.rs index 7f3bb40198..822df99c9c 100644 --- a/common/src/comp/ori.rs +++ b/common/src/comp/ori.rs @@ -62,6 +62,7 @@ impl Ori { Self(Quaternion::slerp(ori1.0, ori2.0, s).normalized()) } + #[must_use] pub fn slerped_towards(self, ori: Ori, s: f32) -> Self { Self::slerp(self, ori, s) } /// Multiply rotation quaternion by `q` @@ -80,6 +81,7 @@ impl Ori { /// /// assert!((ori1.look_dir().dot(*ori2.look_dir()) - 1.0).abs() <= std::f32::EPSILON); /// ``` + #[must_use] pub fn rotated(self, q: Quaternion) -> Self { Self((self.to_quat() * q.normalized()).normalized()) } @@ -100,6 +102,7 @@ impl Ori { /// /// assert!((ori1.look_dir().dot(*ori2.look_dir()) - 1.0).abs() <= std::f32::EPSILON); /// ``` + #[must_use] pub fn prerotated(self, q: Quaternion) -> Self { Self((q.normalized() * self.to_quat()).normalized()) } @@ -148,6 +151,7 @@ impl Ori { self.to_quat() * local } + #[must_use] pub fn to_horizontal(self) -> Self { // We don't use Self::look_dir to avoid the extra normalization step within // Dir's Quaternion Mul impl @@ -210,32 +214,39 @@ impl Ori { pub fn dot(self, other: Self) -> f32 { self.look_vec().dot(other.look_vec()) } + #[must_use] pub fn pitched_up(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_x(angle_radians)) } + #[must_use] pub fn pitched_down(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_x(-angle_radians)) } + #[must_use] pub fn yawed_left(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_z(angle_radians)) } + #[must_use] pub fn yawed_right(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_z(-angle_radians)) } + #[must_use] pub fn rolled_left(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_y(-angle_radians)) } + #[must_use] pub fn rolled_right(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_y(angle_radians)) } /// Returns a version which is rolled such that its up points towards `dir` /// as much as possible without pitching or yawing + #[must_use] pub fn rolled_towards(self, dir: Dir) -> Self { dir.projected(&Plane::from(self.look_dir())) .map_or(self, |dir| self.prerotated(self.up().rotation_between(dir))) @@ -243,6 +254,7 @@ impl Ori { /// Returns a version which has been pitched towards `dir` as much as /// possible without yawing or rolling + #[must_use] pub fn pitched_towards(self, dir: Dir) -> Self { dir.projected(&Plane::from(self.right())) .map_or(self, |dir_| { @@ -252,6 +264,7 @@ impl Ori { /// Returns a version which has been yawed towards `dir` as much as possible /// without pitching or rolling + #[must_use] pub fn yawed_towards(self, dir: Dir) -> Self { dir.projected(&Plane::from(self.up())).map_or(self, |dir_| { self.prerotated(self.look_dir().rotation_between(dir_)) @@ -279,6 +292,7 @@ impl Ori { /// let ang2 = pd_rr.up().angle_between(zenith); /// assert!((ang1 - ang2).abs() <= std::f32::EPSILON); /// ``` + #[must_use] pub fn uprighted(self) -> Self { self.look_dir().into() } fn is_normalized(&self) -> bool { self.0.into_vec4().is_normalized() } diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index 290b11dafe..b4e4f7f493 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -402,6 +402,7 @@ impl ProjectileConstructor { } // TODO: split this to three methods per stat + #[must_use] pub fn modified_projectile(mut self, power: f32, regen: f32, range: f32) -> Self { use ProjectileConstructor::*; match self { diff --git a/common/src/comp/skills.rs b/common/src/comp/skills.rs index ca9da99455..5c9cf61a14 100644 --- a/common/src/comp/skills.rs +++ b/common/src/comp/skills.rs @@ -75,7 +75,7 @@ lazy_static! { let map = SkillTreeMap::load_expect_cloned( "common.skill_trees.skills_skill-groups_manifest", ).0; - map.iter().map(|(sgk, skills)| skills.into_iter().map(move |s| (*s, *sgk))).flatten().collect() + map.iter().flat_map(|(sgk, skills)| skills.into_iter().map(move |s| (*s, *sgk))).collect() }; // Loads the maximum level that a skill can obtain pub static ref SKILL_MAX_LEVEL: HashMap> = { diff --git a/common/src/figure/mod.rs b/common/src/figure/mod.rs index 0fc9ee8cae..ab65d386ee 100644 --- a/common/src/figure/mod.rs +++ b/common/src/figure/mod.rs @@ -81,6 +81,7 @@ impl Segment { } /// Transform cells + #[must_use] pub fn map(mut self, transform: impl Fn(Cell) -> Option) -> Self { for pos in self.full_pos_iter() { if let Some(new) = transform(*self.get(pos).unwrap()) { @@ -92,6 +93,7 @@ impl Segment { } /// Transform cell colors + #[must_use] pub fn map_rgb(self, transform: impl Fn(Rgb) -> Rgb) -> Self { self.map(|cell| { cell.get_color().map(|rgb| { @@ -114,11 +116,13 @@ impl DynaUnionizer { #[allow(clippy::new_without_default)] // TODO: Pending review in #587 pub fn new() -> Self { DynaUnionizer(Vec::new()) } + #[must_use] pub fn add(mut self, dyna: Dyna, offset: Vec3) -> Self { self.0.push((dyna, offset)); self } + #[must_use] pub fn maybe_add(self, maybe: Option<(Dyna, Vec3)>) -> Self { match maybe { Some((dyna, offset)) => self.add(dyna, offset), @@ -175,6 +179,7 @@ impl MatSegment { } /// Transform cells + #[must_use] pub fn map(mut self, transform: impl Fn(MatCell) -> Option) -> Self { for pos in self.full_pos_iter() { if let Some(new) = transform(*self.get(pos).unwrap()) { @@ -186,6 +191,7 @@ impl MatSegment { } /// Transform cell colors + #[must_use] pub fn map_rgb(self, transform: impl Fn(Rgb) -> Rgb) -> Self { self.map(|cell| match cell { MatCell::Normal(data) => Some(MatCell::Normal(CellData { diff --git a/common/src/generation.rs b/common/src/generation.rs index cfc4969157..f1a0a5f181 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -140,6 +140,7 @@ impl EntityConfig { .unwrap_or_else(|e| panic!("Failed to load {}. Error: {:?}", asset_specifier, e)) } + #[must_use] pub fn with_body(mut self, body: BodyBuilder) -> Self { self.body = body; @@ -201,6 +202,7 @@ impl EntityInfo { } /// Helper function for applying config from asset + #[must_use] pub fn with_asset_expect(self, asset_specifier: &str) -> Self { let config = EntityConfig::load_expect_cloned(asset_specifier); @@ -208,6 +210,7 @@ impl EntityInfo { } /// Evaluate and apply EntityConfig + #[must_use] pub fn with_entity_config(mut self, config: EntityConfig, config_asset: Option<&str>) -> Self { let EntityConfig { name, @@ -297,6 +300,7 @@ impl EntityInfo { self } + #[must_use] pub fn do_if(mut self, cond: bool, f: impl FnOnce(Self) -> Self) -> Self { if cond { self = f(self); @@ -304,66 +308,79 @@ impl EntityInfo { self } + #[must_use] pub fn into_waypoint(mut self) -> Self { self.is_waypoint = true; self } + #[must_use] pub fn with_alignment(mut self, alignment: Alignment) -> Self { self.alignment = alignment; self } + #[must_use] pub fn with_body(mut self, body: Body) -> Self { self.body = body; self } + #[must_use] pub fn with_name(mut self, name: impl Into) -> Self { self.name = Some(name.into()); self } + #[must_use] pub fn with_agency(mut self, agency: bool) -> Self { self.has_agency = agency; self } + #[must_use] pub fn with_agent_mark(mut self, agent_mark: agent::Mark) -> Self { self.agent_mark = Some(agent_mark); self } + #[must_use] pub fn with_main_tool(mut self, main_tool: Item) -> Self { self.main_tool = Some(main_tool); self } + #[must_use] pub fn with_second_tool(mut self, second_tool: Item) -> Self { self.second_tool = Some(second_tool); self } + #[must_use] pub fn with_loot_drop(mut self, loot_drop: LootSpec) -> Self { self.loot = loot_drop; self } + #[must_use] pub fn with_scale(mut self, scale: f32) -> Self { self.scale = scale; self } + #[must_use] pub fn with_health_scaling(mut self, level: u16) -> Self { self.health_scaling = Some(level); self } + #[must_use] pub fn with_loadout_asset(mut self, asset: String) -> Self { self.loadout_asset = Some(asset); self } + #[must_use] pub fn with_lazy_loadout( mut self, creator: fn(LoadoutBuilder, Option<&trade::SiteInformation>) -> LoadoutBuilder, @@ -372,11 +389,13 @@ impl EntityInfo { self } + #[must_use] pub fn with_skillset_asset(mut self, asset: String) -> Self { self.skillset_asset = Some(asset); self } + #[must_use] pub fn with_automatic_name(mut self) -> Self { let npc_names = NPC_NAMES.read(); let name = match &self.body { @@ -402,7 +421,8 @@ impl EntityInfo { self } - // map contains price+amount + /// map contains price+amount + #[must_use] pub fn with_economy(mut self, e: &SiteInformation) -> Self { self.trading_information = Some(e.clone()); self diff --git a/common/src/grid.rs b/common/src/grid.rs index 625e5d8b76..e7cefcb74d 100644 --- a/common/src/grid.rs +++ b/common/src/grid.rs @@ -18,8 +18,7 @@ impl Grid { pub fn populate_from(size: Vec2, mut f: impl FnMut(Vec2) -> T) -> Self { Self { cells: (0..size.y) - .map(|y| (0..size.x).map(move |x| Vec2::new(x, y))) - .flatten() + .flat_map(|y| (0..size.x).map(move |x| Vec2::new(x, y))) .map(&mut f) .collect(), size, @@ -79,16 +78,14 @@ impl Grid { pos: Vec2, size: Vec2, ) -> impl Iterator, &T)>> + '_ { - (0..size.x) - .map(move |x| { - (0..size.y).map(move |y| { - Some(( - pos + Vec2::new(x, y), - &self.cells[self.idx(pos + Vec2::new(x, y))?], - )) - }) + (0..size.x).flat_map(move |x| { + (0..size.y).map(move |y| { + Some(( + pos + Vec2::new(x, y), + &self.cells[self.idx(pos + Vec2::new(x, y))?], + )) }) - .flatten() + }) } pub fn raw(&self) -> &[T] { &self.cells } diff --git a/common/src/path.rs b/common/src/path.rs index ad77ca2fd3..5198624a77 100644 --- a/common/src/path.rs +++ b/common/src/path.rs @@ -248,8 +248,7 @@ impl Route { }) .unwrap_or_else(|| { (0..2) - .map(|i| (0..2).map(move |j| Vec2::new(i, j))) - .flatten() + .flat_map(|i| (0..2).map(move |j| Vec2::new(i, j))) .map(|rpos| block_pos + rpos) .map(|block_pos| { let block_posf = block_pos.xy().map(|e| e as f32); diff --git a/common/src/ray.rs b/common/src/ray.rs index 53bf7a9bc2..10534a0868 100644 --- a/common/src/ray.rs +++ b/common/src/ray.rs @@ -55,11 +55,13 @@ where } } + #[must_use] pub fn max_iter(mut self, max_iter: usize) -> Self { self.max_iter = max_iter; self } + #[must_use] pub fn ignore_error(mut self) -> Self { self.ignore_error = true; self diff --git a/common/src/states/combo_melee.rs b/common/src/states/combo_melee.rs index a1fd2fc353..e47cda8add 100644 --- a/common/src/states/combo_melee.rs +++ b/common/src/states/combo_melee.rs @@ -71,6 +71,7 @@ impl Stage { } } + #[must_use] pub fn adjusted_by_stats(mut self, stats: Stats) -> Self { if let Some(CombatEffect::Buff(CombatBuff { kind: _, @@ -101,6 +102,7 @@ impl Stage { } // TODO: name it as using knockback + #[must_use] pub fn modify_strike(mut self, knockback_mult: f32) -> Self { self.knockback *= knockback_mult; self diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index ef8f2ade62..c367a8c05b 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -341,6 +341,7 @@ impl Block { /// If this block is a fluid, replace its sprite. #[inline] + #[must_use] pub fn with_sprite(mut self, sprite: SpriteKind) -> Self { if !self.is_filled() { self.attr[0] = sprite as u8; @@ -350,6 +351,7 @@ impl Block { /// If this block can have orientation, give it a new orientation. #[inline] + #[must_use] pub fn with_ori(mut self, ori: u8) -> Option { if self.get_sprite().map(|s| s.has_ori()).unwrap_or(false) { self.attr[1] = (self.attr[1] & !0b111) | (ori & 0b111); @@ -361,6 +363,7 @@ impl Block { /// Remove the terrain sprite or solid aspects of a block #[inline] + #[must_use] pub fn into_vacant(self) -> Self { if self.is_fluid() { Block::new(self.kind(), Rgb::zero()) @@ -373,6 +376,7 @@ impl Block { /// Attempt to convert a [`u32`] to a block #[inline] + #[must_use] pub fn from_u32(x: u32) -> Option { let [bk, r, g, b] = x.to_le_bytes(); Some(Self { diff --git a/common/src/terrain/chonk.rs b/common/src/terrain/chonk.rs index 277d0380c3..a4c2e60766 100644 --- a/common/src/terrain/chonk.rs +++ b/common/src/terrain/chonk.rs @@ -79,12 +79,11 @@ impl Chonk { .iter() .enumerate() .filter(|(_, sc)| sc.num_groups() > 0) - .map(move |(i, sc)| { + .flat_map(move |(i, sc)| { let z_offset = self.z_offset + i as i32 * SubChunkSize::::SIZE.z as i32; sc.vol_iter(Vec3::zero(), SubChunkSize::::SIZE.map(|e| e as i32)) .map(move |(pos, vox)| (pos + Vec3::unit_z() * z_offset, vox)) }) - .flatten() } // Returns the index (in self.sub_chunks) of the SubChunk that contains diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 21bbbfe91f..e6a283b237 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -104,6 +104,7 @@ impl Structure { StructuresGroup::load_expect(&["world.manifests.", specifier].concat()) } + #[must_use] pub fn with_center(mut self, center: Vec3) -> Self { self.center = center; self diff --git a/common/src/trade.rs b/common/src/trade.rs index d666fce609..4d8bd721a6 100644 --- a/common/src/trade.rs +++ b/common/src/trade.rs @@ -363,7 +363,7 @@ impl SitePrices { .map(|(slot, amount)| { inventories[who] .as_ref() - .map(|ri| { + .and_then(|ri| { ri.inventory.get(slot).map(|item| { let (material, factor) = TradePricing::get_material(&item.name); self.values.get(&material).cloned().unwrap_or_default() @@ -372,7 +372,6 @@ impl SitePrices { * if reduce { material.trade_margin() } else { 1.0 } }) }) - .flatten() .unwrap_or_default() }) .sum() diff --git a/common/src/util/dir.rs b/common/src/util/dir.rs index 34a299dd9b..90742b4b1e 100644 --- a/common/src/util/dir.rs +++ b/common/src/util/dir.rs @@ -83,6 +83,7 @@ impl Dir { Self(slerp_normalized(from.0, to.0, factor)) } + #[must_use] pub fn slerped_to(self, to: Self, factor: f32) -> Self { Self(slerp_normalized(self.0, to.0, factor)) } diff --git a/common/src/vol.rs b/common/src/vol.rs index 42aeecf0be..2fc8ef4477 100644 --- a/common/src/vol.rs +++ b/common/src/vol.rs @@ -17,6 +17,7 @@ pub trait Vox: Sized + Clone + PartialEq { fn empty() -> Self; fn is_empty(&self) -> bool; + #[must_use] fn or(self, other: Self) -> Self { if self.is_empty() { other } else { self } } } diff --git a/common/src/volumes/scaled.rs b/common/src/volumes/scaled.rs index 6ff23c4f6b..a0400a5a3b 100644 --- a/common/src/volumes/scaled.rs +++ b/common/src/volumes/scaled.rs @@ -38,8 +38,9 @@ where }) }; range_iter(0) - .map(|i| range_iter(1).map(move |j| range_iter(2).map(move |k| Vec3::new(i, j, k)))) - .flatten() + .flat_map(|i| { + range_iter(1).map(move |j| range_iter(2).map(move |k| Vec3::new(i, j, k))) + }) .flatten() .map(|offs| self.inner.get(pos + offs)) .find(|vox| vox.as_ref().map(|v| !v.is_empty()).unwrap_or(false)) diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 433f95df49..3a06dbc0a2 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -268,6 +268,7 @@ impl State { } /// Register a component with the state's ECS. + #[must_use] pub fn with_component(mut self) -> Self where ::Storage: Default, diff --git a/common/systems/src/buff.rs b/common/systems/src/buff.rs index 47bff77b11..559b6a5fea 100644 --- a/common/systems/src/buff.rs +++ b/common/systems/src/buff.rs @@ -215,19 +215,16 @@ impl<'a> System<'a> for Sys { ModifierKind::Additive => *accumulated, ModifierKind::Fractional => health.maximum() * *accumulated, }; - let damage_contributor = by - .map(|uid| { - read_data - .uid_allocator - .retrieve_entity_internal(uid.0) - .map(|entity| { - DamageContributor::new( - uid, - read_data.groups.get(entity).cloned(), - ) - }) - }) - .flatten(); + let damage_contributor = by.and_then(|uid| { + read_data.uid_allocator.retrieve_entity_internal(uid.0).map( + |entity| { + DamageContributor::new( + uid, + read_data.groups.get(entity).cloned(), + ) + }, + ) + }); server_emitter.emit(ServerEvent::HealthChange { entity, change: HealthChange { diff --git a/common/systems/src/phys.rs b/common/systems/src/phys.rs index cbd26a0019..42ebfc587b 100644 --- a/common/systems/src/phys.rs +++ b/common/systems/src/phys.rs @@ -1952,7 +1952,8 @@ fn closest_points(n: LineSegment2, m: LineSegment2) -> (Vec2, Vec // Check to see whether the lines are parallel if !t.is_finite() || !u.is_finite() { - core::array::IntoIter::new([ + // TODO: can use postfix .into_iter() when switching to Rust 2021 + IntoIterator::into_iter([ (n.projected_point(m.start), m.start), (n.projected_point(m.end), m.end), (n.start, m.projected_point(n.start)), diff --git a/rust-toolchain b/rust-toolchain index 98f2112ea9..fdace0b319 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2021-11-24 +nightly-2021-12-19 diff --git a/server/src/cmd.rs b/server/src/cmd.rs index cf88f0632d..023f25f1fd 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -471,7 +471,7 @@ fn handle_give_item( ) -> CmdResult<()> { if let (Some(item_name), give_amount_opt) = parse_args!(args, String, u32) { let give_amount = give_amount_opt.unwrap_or(1); - if let Ok(item) = Item::new_from_asset(&item_name.replace('/', ".").replace("\\", ".")) { + if let Ok(item) = Item::new_from_asset(&item_name.replace('/', ".").replace('\\', ".")) { let mut item: Item = item; let mut res = Ok(()); @@ -2805,16 +2805,16 @@ fn handle_disconnect_all_players( // TODO: This logging and verification of admin commands would be better moved // to a more generic method used for auditing -all- admin commands. - let player_name; - if let Some(player) = players.get(client) { - player_name = &*player.alias; + + let player_name = if let Some(player) = players.get(client) { + &*player.alias } else { warn!( "Failed to get player name for admin who used /disconnect_all_players - ignoring \ command." ); return Err("You do not exist, so you cannot use this command".to_string()); - } + }; info!( "Disconnecting all clients due to admin command from {}", diff --git a/server/src/events/trade.rs b/server/src/events/trade.rs index f9ba077dd9..5ab8fef8aa 100644 --- a/server/src/events/trade.rs +++ b/server/src/events/trade.rs @@ -426,15 +426,13 @@ mod tests { mockworld.insert(AbilityMap::default()); mockworld.register::(); mockworld.register::(); - let player: EcsEntity; - let merchant: EcsEntity; - player = mockworld + let player: EcsEntity = mockworld .create_entity() .with(Inventory::new_empty()) .build(); - merchant = mockworld + let merchant: EcsEntity = mockworld .create_entity() .with(Inventory::new_empty()) .build(); diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index 05431bb41c..336c70d755 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -131,13 +131,11 @@ impl StateExt for State { let stats = self.ecs().read_storage::(); let groups = self.ecs().read_storage::(); - let damage_contributor = source - .map(|uid| { - self.ecs().entity_from_uid(uid.0).map(|attacker_entity| { - DamageContributor::new(uid, groups.get(attacker_entity).cloned()) - }) + let damage_contributor = source.and_then(|uid| { + self.ecs().entity_from_uid(uid.0).map(|attacker_entity| { + DamageContributor::new(uid, groups.get(attacker_entity).cloned()) }) - .flatten(); + }); let time = self.ecs().read_resource::