From b21423ae01cda2fec404604f9dbcd1526c7fea16 Mon Sep 17 00:00:00 2001 From: Ludovic Marie Date: Sat, 24 Oct 2026 11:31:10 +0200 Subject: [PATCH] Keep only the Clippy rewrites that read as well on stable CI runs stable Clippy (1.99), which is clean on main. The #[expect(clippy::boxed_local)] in streaming.rs is unfulfilled there and fails CI under -D warnings, so it goes. Also back out the rewrites that only satisfied Rust 1.90's Clippy and read worse: the dragon's range helper and its test, the axolotl test's restated formula, and two De Morgan expansions (first_person_probe, explosion). Co-Authored-By: Claude Opus 5.5 --- .../examples/probe/first_person_probe.rs | 2 +- crates/horizon-client/src/game/dragon.rs | 28 +++---------------- crates/horizon-client/src/game/explosion.rs | 2 +- crates/horizon-client/src/mobs/axolotl.rs | 17 +++++------ crates/horizon-client/src/streaming.rs | 6 ---- 5 files changed, 13 insertions(+), 42 deletions(-) diff --git a/crates/horizon-client/examples/probe/first_person_probe.rs b/crates/horizon-client/examples/probe/first_person_probe.rs index 38829714c..cb4c38e58 100644 --- a/crates/horizon-client/examples/probe/first_person_probe.rs +++ b/crates/horizon-client/examples/probe/first_person_probe.rs @@ -203,7 +203,7 @@ impl HandWorld for Probe<'_> { let item = self.stack(Hand::Main).effective().0; // Item.canDestroyBlock: swords' tools cannot destroy in creative. let sword = item.ends_with("_sword"); - let ok = (!sword || !self.creative) && !self.is_air(pos); + let ok = !(sword && self.creative) && !self.is_air(pos); if ok { self.blocks.insert(pos, "minecraft:air".into()); } diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index cd2de3736..c6f5d419b 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -27,12 +27,6 @@ const CRYSTAL_IDS: u32 = SPECIAL + 16; const FIGHT_FILE: &str = "data/minecraft/ender_dragon_fight.dat"; const MAX_HEALTH: f32 = 200.0; -/// Preserve the ordered double comparisons from vanilla: a NaN squared -/// distance fails both comparisons and must not be treated as out of range. -fn target_distance_outside_range(distance_squared: f64) -> bool { - !distance_squared.is_nan() && !(100.0..=22500.0).contains(&distance_squared) -} - #[derive(Default)] pub(super) struct Fight { loaded: bool, @@ -1292,7 +1286,7 @@ impl Game<'_> { clockwise, } => { let dt = far(*target); - if target_distance_outside_range(dt) || collided { + if dt < 100.0 || dt > 22500.0 || collided { let done = path.as_ref().is_some_and(|p| p.0.done()); let mut chosen = false; if done { @@ -1362,7 +1356,7 @@ impl Game<'_> { *target = Some(Vec3::new(pp.x, pp.y + ho, pp.z)); } let dt = far(*target); - if target_distance_outside_range(dt) { + if dt < 100.0 || dt > 22500.0 { if path.as_ref().is_none_or(|p| p.0.done()) { *path = self.ring_path(clockwise).map(PathBox); } @@ -1399,7 +1393,7 @@ impl Game<'_> { } Phase::LandingApproach { path, target } => { let dt = far(*target); - if target_distance_outside_range(dt) || collided { + if dt < 100.0 || dt > 22500.0 || collided { if path.as_ref().is_none_or(|p| p.0.done()) { let current = self.closest_node(pos.x, pos.y, pos.z); // NEAR_EGG_TARGETING: the enemy nearest the egg. @@ -1583,7 +1577,7 @@ impl Game<'_> { } } else { let dt = far(*target); - if target_distance_outside_range(dt) { + if dt < 100.0 || dt > 22500.0 { *since += 1; } } @@ -3269,18 +3263,4 @@ mod tests { let t = nearest_enemy(&players, false, Vec3::new(9.0, 64.0, 0.0), None, |_| true); assert_eq!(t.map(|p| p.who), Some(FightWho::Host)); } - #[test] - fn target_distance_respects_nan_and_exact_boundaries() { - for (distance, expected) in [ - (f64::NAN, false), - (f64::NEG_INFINITY, true), - (99.0, true), - (100.0, false), - (22500.0, false), - (22501.0, true), - (f64::INFINITY, true), - ] { - assert_eq!(super::target_distance_outside_range(distance), expected); - } - } } diff --git a/crates/horizon-client/src/game/explosion.rs b/crates/horizon-client/src/game/explosion.rs index e3baa76fc..6ecba3a54 100644 --- a/crates/horizon-client/src/game/explosion.rs +++ b/crates/horizon-client/src/game/explosion.rs @@ -306,7 +306,7 @@ impl Game<'_> { { outcome = o; } - if !spectator && (!creative || !flying) { + if !spectator && !(creative && flying) { p.velocity = Vec3::new( p.velocity.x + dir[0] * power, p.velocity.y + dir[1] * power, diff --git a/crates/horizon-client/src/mobs/axolotl.rs b/crates/horizon-client/src/mobs/axolotl.rs index e4a639768..55f15717c 100644 --- a/crates/horizon-client/src/mobs/axolotl.rs +++ b/crates/horizon-client/src/mobs/axolotl.rs @@ -166,16 +166,13 @@ mod axolotl_parity_tests { ] { let mut expected = LegacyRandom::new(seed); let mut actual = LegacyRandom::new(seed); - // The second draw is intentionally consumed even though - // the fixed 4.0 / 14.0 threshold always makes this branch - // true. Removing it changes the native RNG sequence. - let first_gate = !no_ai && expected.next_int_bound(3).unwrap() == 0; - let result = if first_gate { - let _second_draw = expected.next_int_bound(3).unwrap(); - water && entity && !already - } else { - false - }; + let result = !no_ai + && expected.next_int_bound(3).unwrap() == 0 + && ((expected.next_int_bound(3).unwrap() as f32) < 2.0 || 4.0f32 / 14.0 < 0.5) + && 2.0 < 4.0 + && water + && entity + && !already; assert_eq!( roll_play_dead(&mut actual, no_ai, 4.0, 14.0, 2.0, water, entity, already), result diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 92d37483b..15ed1674e 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -641,12 +641,6 @@ impl Streaming { }); self.shared.ready.notify_one(); } - // Proto arrays are large; keep ownership of the incoming heap allocation - // instead of moving all nine chunks onto a transient stack frame. - #[expect( - clippy::boxed_local, - reason = "keep nine large Proto values heap resident" - )] fn receive_decorated(&mut self, x: i32, z: i32, region: Box<[Proto; 9]>) { self.generation_scan.exhausted = false; self.decorating -= 1;