From 844185baf540d376771937eff23712fd36882004 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Mon, 5 Dec 2022 20:02:47 +0000 Subject: [PATCH] use built-in 'assert' --- crates/fj-kernel/src/partial/merge.rs | 7 ++++--- crates/fj-kernel/src/storage/blocks.rs | 4 +--- crates/fj-math/src/line.rs | 7 ++++--- crates/fj-window/src/event_loop_handler.rs | 7 ++++--- tools/autolib/src/lib.rs | 5 ++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/partial/merge.rs b/crates/fj-kernel/src/partial/merge.rs index dac76cf55..f41a59812 100644 --- a/crates/fj-kernel/src/partial/merge.rs +++ b/crates/fj-kernel/src/partial/merge.rs @@ -46,9 +46,10 @@ where } // We know that `self != other`, or we wouldn't have made it here. - if self.is_some() && other.is_some() { - panic!("Can't merge two `Option`s that are both `Some`") - } + assert!( + self.is_none() || other.is_none(), + "Can't merge two `Option`s that are both `Some`" + ); self.xor(other) } diff --git a/crates/fj-kernel/src/storage/blocks.rs b/crates/fj-kernel/src/storage/blocks.rs index 474b3d002..7a67b5c42 100644 --- a/crates/fj-kernel/src/storage/blocks.rs +++ b/crates/fj-kernel/src/storage/blocks.rs @@ -94,9 +94,7 @@ impl Block { pub fn insert(&mut self, index: ObjectIndex, object: T) { let slot = &mut self.objects[index.0]; - if slot.is_some() { - panic!("Attempting to overwrite object in store") - } + assert!(slot.is_none(), "Attempting to overwrite object in store"); *slot = Some(object); } diff --git a/crates/fj-math/src/line.rs b/crates/fj-math/src/line.rs index 5a3c7a1a2..bec71a29c 100644 --- a/crates/fj-math/src/line.rs +++ b/crates/fj-math/src/line.rs @@ -21,9 +21,10 @@ impl Line { origin: Point, direction: Vector, ) -> Self { - if direction.magnitude() == Scalar::ZERO { - panic!("Can't construct `Line`. Direction is zero: {direction:?}"); - } + assert!( + direction.magnitude() != Scalar::ZERO, + "Can't construct `Line`. Direction is zero: {direction:?}" + ); Self { origin, direction } } diff --git a/crates/fj-window/src/event_loop_handler.rs b/crates/fj-window/src/event_loop_handler.rs index 3465f693b..1e311d1d8 100644 --- a/crates/fj-window/src/event_loop_handler.rs +++ b/crates/fj-window/src/event_loop_handler.rs @@ -45,9 +45,10 @@ impl EventLoopHandler { let event = events .try_recv() .map_err(|err| { - if err.is_disconnected() { - panic!("Expected channel to never disconnect"); - } + assert!( + !err.is_disconnected(), + "Expected channel to never disconnect" + ); }) .ok(); diff --git a/tools/autolib/src/lib.rs b/tools/autolib/src/lib.rs index b236addac..8a307281e 100644 --- a/tools/autolib/src/lib.rs +++ b/tools/autolib/src/lib.rs @@ -9,7 +9,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result> { version.as_str(), ); }) - .filter_map(|m| { + .find_map(|m| { let version = semver::Version::parse(m.as_str()).ok(); if version.is_some() { @@ -19,8 +19,7 @@ pub fn find_version_in_str(s: &str) -> anyhow::Result> { } version - }) - .next(); + }); Ok(version) }