forked from extern/nushell
Remove unwraps (#1153)
* Remove a batch of unwraps * finish another batch
This commit is contained in:
@ -254,7 +254,7 @@ pub struct ExpandTracer {
|
||||
|
||||
impl ExpandTracer {
|
||||
pub fn print(&self, source: Text) -> PrintTracer {
|
||||
let root = self.frame_stack.get(0).unwrap().to_tree_frame(&source);
|
||||
let root = self.frame_stack[0].to_tree_frame(&source);
|
||||
|
||||
PrintTracer { root, source }
|
||||
}
|
||||
|
@ -42,7 +42,11 @@ impl CompareOperator {
|
||||
|
||||
impl From<&str> for CompareOperator {
|
||||
fn from(input: &str) -> CompareOperator {
|
||||
CompareOperator::from_str(input).unwrap()
|
||||
if let Ok(output) = CompareOperator::from_str(input) {
|
||||
output
|
||||
} else {
|
||||
unreachable!("Internal error: CompareOperator from failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +94,11 @@ impl EvaluationOperator {
|
||||
|
||||
impl From<&str> for EvaluationOperator {
|
||||
fn from(input: &str) -> EvaluationOperator {
|
||||
EvaluationOperator::from_str(input).unwrap()
|
||||
if let Ok(output) = EvaluationOperator::from_str(input) {
|
||||
output
|
||||
} else {
|
||||
unreachable!("Internal error: EvaluationOperator 'from' failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,13 +148,21 @@ macro_rules! primitive_decimal {
|
||||
$(
|
||||
impl From<$ty> for Number {
|
||||
fn from(decimal: $ty) -> Number {
|
||||
Number::Decimal(BigDecimal::$from(decimal).unwrap())
|
||||
if let Some(num) = BigDecimal::$from(decimal) {
|
||||
Number::Decimal(num)
|
||||
} else {
|
||||
unreachable!("Internal error: BigDecimal 'from' failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&$ty> for Number {
|
||||
fn from(decimal: &$ty) -> Number {
|
||||
Number::Decimal(BigDecimal::$from(*decimal).unwrap())
|
||||
if let Some(num) = BigDecimal::$from(*decimal) {
|
||||
Number::Decimal(num)
|
||||
} else {
|
||||
unreachable!("Internal error: BigDecimal 'from' failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
)*
|
||||
@ -909,11 +917,13 @@ pub fn module(input: NomSpan) -> IResult<NomSpan, TokenNode> {
|
||||
}
|
||||
|
||||
fn parse_int<T>(frag: &str, neg: Option<T>) -> i64 {
|
||||
let int = FromStr::from_str(frag).unwrap();
|
||||
|
||||
match neg {
|
||||
None => int,
|
||||
Some(_) => -int,
|
||||
if let Ok(int) = FromStr::from_str(frag) {
|
||||
match neg {
|
||||
None => int,
|
||||
Some(_) => -int,
|
||||
}
|
||||
} else {
|
||||
unreachable!("Internal error: parse_int failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -323,10 +323,13 @@ impl TokenTreeBuilder {
|
||||
|
||||
let mut input = input.into_iter();
|
||||
|
||||
let head = input.next().unwrap();
|
||||
let tail = input.collect();
|
||||
if let Some(head) = input.next() {
|
||||
let tail = input.collect();
|
||||
|
||||
CallNode::new(Box::new(head), tail).spanned(span.into())
|
||||
CallNode::new(Box::new(head), tail).spanned(span.into())
|
||||
} else {
|
||||
unreachable!("Internal error: spanned_call failed")
|
||||
}
|
||||
}
|
||||
|
||||
fn consume_delimiter(
|
||||
|
@ -88,9 +88,19 @@ impl RawNumber {
|
||||
|
||||
pub(crate) fn to_number(self, source: &Text) -> Number {
|
||||
match self {
|
||||
RawNumber::Int(tag) => Number::Int(BigInt::from_str(tag.slice(source)).unwrap()),
|
||||
RawNumber::Int(tag) => {
|
||||
if let Ok(int) = BigInt::from_str(tag.slice(source)) {
|
||||
Number::Int(int)
|
||||
} else {
|
||||
unreachable!("Internal error: to_number failed")
|
||||
}
|
||||
}
|
||||
RawNumber::Decimal(tag) => {
|
||||
Number::Decimal(BigDecimal::from_str(tag.slice(source)).unwrap())
|
||||
if let Ok(decimal) = BigDecimal::from_str(tag.slice(source)) {
|
||||
Number::Decimal(decimal)
|
||||
} else {
|
||||
unreachable!("Internal error: to_number failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user