mirror of
				https://github.com/rm-dr/daisy
				synced 2025-11-03 15:04:25 -08:00 
			
		
		
		
	Cleaned up a few panic!()s
This commit is contained in:
		@ -145,7 +145,7 @@ pub fn do_command(
 | 
				
			|||||||
				t = format!("{}{}", color::Fg(color::Magenta), style::Bold)
 | 
									t = format!("{}{}", color::Fg(color::Magenta), style::Bold)
 | 
				
			||||||
			)?;
 | 
								)?;
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		_ => panic!("Bad command!")
 | 
							_ => unreachable!("Bad command!")
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return Ok(());
 | 
						return Ok(());
 | 
				
			||||||
 | 
				
			|||||||
@ -89,7 +89,7 @@ fn do_expression(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		match g {
 | 
							match g {
 | 
				
			||||||
			Ok(_) => panic!(),
 | 
								Ok(_) => unreachable!(),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Err(EvalError::TooBig) => {
 | 
								Err(EvalError::TooBig) => {
 | 
				
			||||||
				write!(
 | 
									write!(
 | 
				
			||||||
 | 
				
			|||||||
@ -54,6 +54,6 @@ pub fn eval_function(f: &Function, args: &VecDeque<Expression>) -> Result<Expres
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		Function::ToBase
 | 
							Function::ToBase
 | 
				
			||||||
		| Function::NoUnit
 | 
							| Function::NoUnit
 | 
				
			||||||
		=> panic!()
 | 
							=> unreachable!()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -28,7 +28,7 @@ fn push_token(g: &mut VecDeque<Token>, t: Option<Token>, stop_i: usize) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		Token::Group(_,_)
 | 
							Token::Group(_,_)
 | 
				
			||||||
		| Token::Container(_)
 | 
							| Token::Container(_)
 | 
				
			||||||
		=> panic!()
 | 
							=> unreachable!()
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -96,7 +96,7 @@ impl Token {
 | 
				
			|||||||
			| Token::GroupStart(_)
 | 
								| Token::GroupStart(_)
 | 
				
			||||||
			| Token::GroupEnd(_)
 | 
								| Token::GroupEnd(_)
 | 
				
			||||||
			| Token::Group(_, _)
 | 
								| Token::Group(_, _)
 | 
				
			||||||
			=> panic!()
 | 
								=> panic!("This token cannot be converted to an expression")
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -255,7 +255,7 @@ impl Add for Quantity {
 | 
				
			|||||||
	type Output = Self;
 | 
						type Output = Self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fn add(self, other: Self) -> Self::Output {
 | 
						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;
 | 
							let mut o = other;
 | 
				
			||||||
		if self.unit != o.unit {
 | 
							if self.unit != o.unit {
 | 
				
			||||||
@ -271,7 +271,7 @@ impl Add for Quantity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl AddAssign for Quantity where {
 | 
					impl AddAssign for Quantity where {
 | 
				
			||||||
	fn add_assign(&mut self, other: Self) {
 | 
						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;
 | 
							let mut o = other;
 | 
				
			||||||
		if self.unit != o.unit {
 | 
							if self.unit != o.unit {
 | 
				
			||||||
@ -286,7 +286,7 @@ impl Sub for Quantity {
 | 
				
			|||||||
	type Output = Self;
 | 
						type Output = Self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fn sub(self, other: Self) -> Self::Output {
 | 
						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;
 | 
							let mut o = other;
 | 
				
			||||||
		if self.unit != o.unit {
 | 
							if self.unit != o.unit {
 | 
				
			||||||
@ -302,7 +302,7 @@ impl Sub for Quantity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl SubAssign for Quantity where {
 | 
					impl SubAssign for Quantity where {
 | 
				
			||||||
	fn sub_assign(&mut self, other: Self) {
 | 
						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;
 | 
							let mut o = other;
 | 
				
			||||||
		if self.unit != o.unit {
 | 
							if self.unit != o.unit {
 | 
				
			||||||
@ -369,8 +369,8 @@ impl Rem<Quantity> for Quantity {
 | 
				
			|||||||
	type Output = Self;
 | 
						type Output = Self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fn rem(self, other: Quantity) -> Self::Output {
 | 
						fn rem(self, other: Quantity) -> Self::Output {
 | 
				
			||||||
		if !self.unit.unitless() { panic!() }
 | 
							if !self.unit.unitless() { panic!("Tried to % a quantity with units") }
 | 
				
			||||||
		if !other.unit.unitless() { panic!() }
 | 
							if !other.unit.unitless() { panic!("Tried to % by a quantity with units") }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Quantity {
 | 
							Quantity {
 | 
				
			||||||
			scalar: self.scalar % other.scalar,
 | 
								scalar: self.scalar % other.scalar,
 | 
				
			||||||
@ -389,7 +389,7 @@ impl PartialEq for Quantity {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl PartialOrd for Quantity {
 | 
					impl PartialOrd for Quantity {
 | 
				
			||||||
	fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
 | 
						fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
 | 
				
			||||||
		if self.unit != other.unit { panic!() }
 | 
							if self.unit != other.unit { panic!("Tried to compare incompatible units") }
 | 
				
			||||||
		self.scalar.partial_cmp(&other.scalar)
 | 
							self.scalar.partial_cmp(&other.scalar)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -52,7 +52,7 @@ impl ToString for Unit {
 | 
				
			|||||||
						'7' => '⁷',
 | 
											'7' => '⁷',
 | 
				
			||||||
						'8' => '⁸',
 | 
											'8' => '⁸',
 | 
				
			||||||
						'9' => '⁹',
 | 
											'9' => '⁹',
 | 
				
			||||||
						_ => panic!()
 | 
											_ => unreachable!()
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				t.push('·');
 | 
									t.push('·');
 | 
				
			||||||
@ -90,7 +90,7 @@ impl ToString for Unit {
 | 
				
			|||||||
						'7' => '⁷',
 | 
											'7' => '⁷',
 | 
				
			||||||
						'8' => '⁸',
 | 
											'8' => '⁸',
 | 
				
			||||||
						'9' => '⁹',
 | 
											'9' => '⁹',
 | 
				
			||||||
						_ => panic!()
 | 
											_ => unreachable!()
 | 
				
			||||||
					});
 | 
										});
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				b.push('·');
 | 
									b.push('·');
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user