From be043af4f00121c45cbd7dff074557c8b2b3b6ea Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 28 Jul 2023 09:36:25 -0700 Subject: [PATCH] Cleaned up a few panic!()s --- src/command/mod.rs | 2 +- src/entry/unix/unix.rs | 2 +- src/evaluate/function.rs | 2 +- src/parser/stage/tokenize.rs | 2 +- src/parser/token.rs | 2 +- src/quantity/quantity.rs | 14 +++++++------- src/quantity/unit/unit.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/command/mod.rs b/src/command/mod.rs index 03d2101..e55c6dd 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -145,7 +145,7 @@ pub fn do_command( t = format!("{}{}", color::Fg(color::Magenta), style::Bold) )?; }, - _ => panic!("Bad command!") + _ => unreachable!("Bad command!") }; return Ok(()); diff --git a/src/entry/unix/unix.rs b/src/entry/unix/unix.rs index 35b7335..4318320 100644 --- a/src/entry/unix/unix.rs +++ b/src/entry/unix/unix.rs @@ -89,7 +89,7 @@ fn do_expression( } else { match g { - Ok(_) => panic!(), + Ok(_) => unreachable!(), Err(EvalError::TooBig) => { write!( diff --git a/src/evaluate/function.rs b/src/evaluate/function.rs index 11d58b1..a760697 100644 --- a/src/evaluate/function.rs +++ b/src/evaluate/function.rs @@ -54,6 +54,6 @@ pub fn eval_function(f: &Function, args: &VecDeque) -> Result panic!() + => unreachable!() } } \ No newline at end of file diff --git a/src/parser/stage/tokenize.rs b/src/parser/stage/tokenize.rs index 00e5ce0..470631d 100644 --- a/src/parser/stage/tokenize.rs +++ b/src/parser/stage/tokenize.rs @@ -28,7 +28,7 @@ fn push_token(g: &mut VecDeque, t: Option, stop_i: usize) { Token::Group(_,_) | Token::Container(_) - => panic!() + => unreachable!() }; diff --git a/src/parser/token.rs b/src/parser/token.rs index eb54a69..3648ea5 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -96,7 +96,7 @@ impl Token { | Token::GroupStart(_) | Token::GroupEnd(_) | Token::Group(_, _) - => panic!() + => panic!("This token cannot be converted to an expression") }; } diff --git a/src/quantity/quantity.rs b/src/quantity/quantity.rs index 2df2d11..24fd39b 100644 --- a/src/quantity/quantity.rs +++ b/src/quantity/quantity.rs @@ -255,7 +255,7 @@ impl Add for Quantity { type Output = Self; fn add(self, other: Self) -> Self::Output { - if !self.unit.compatible_with(&other.unit) { panic!() } + if !self.unit.compatible_with(&other.unit) { panic!("Tried to add incompatible units") } let mut o = other; if self.unit != o.unit { @@ -271,7 +271,7 @@ impl Add for Quantity { impl AddAssign for Quantity where { fn add_assign(&mut self, other: Self) { - if !self.unit.compatible_with(&other.unit) { panic!() } + if !self.unit.compatible_with(&other.unit) { panic!("Tried to addassign incompatible units") } let mut o = other; if self.unit != o.unit { @@ -286,7 +286,7 @@ impl Sub for Quantity { type Output = Self; fn sub(self, other: Self) -> Self::Output { - if !self.unit.compatible_with(&other.unit) { panic!() } + if !self.unit.compatible_with(&other.unit) { panic!("Tried to subtract incompatible units") } let mut o = other; if self.unit != o.unit { @@ -302,7 +302,7 @@ impl Sub for Quantity { impl SubAssign for Quantity where { fn sub_assign(&mut self, other: Self) { - if !self.unit.compatible_with(&other.unit) { panic!() } + if !self.unit.compatible_with(&other.unit) { panic!("Tried to subassign incompatible units") } let mut o = other; if self.unit != o.unit { @@ -369,8 +369,8 @@ impl Rem for Quantity { type Output = Self; fn rem(self, other: Quantity) -> Self::Output { - if !self.unit.unitless() { panic!() } - if !other.unit.unitless() { panic!() } + if !self.unit.unitless() { panic!("Tried to % a quantity with units") } + if !other.unit.unitless() { panic!("Tried to % by a quantity with units") } Quantity { scalar: self.scalar % other.scalar, @@ -389,7 +389,7 @@ impl PartialEq for Quantity { impl PartialOrd for Quantity { fn partial_cmp(&self, other: &Self) -> Option { - if self.unit != other.unit { panic!() } + if self.unit != other.unit { panic!("Tried to compare incompatible units") } self.scalar.partial_cmp(&other.scalar) } } \ No newline at end of file diff --git a/src/quantity/unit/unit.rs b/src/quantity/unit/unit.rs index ef06faa..c050af5 100644 --- a/src/quantity/unit/unit.rs +++ b/src/quantity/unit/unit.rs @@ -52,7 +52,7 @@ impl ToString for Unit { '7' => '⁷', '8' => '⁸', '9' => '⁹', - _ => panic!() + _ => unreachable!() }); } t.push('·'); @@ -90,7 +90,7 @@ impl ToString for Unit { '7' => '⁷', '8' => '⁸', '9' => '⁹', - _ => panic!() + _ => unreachable!() }); } b.push('·');