From d3b4d7da9a801dac3af6a3cf52eb55af83adc5f5 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 12 Jun 2023 16:43:49 +0200 Subject: More `bail!` usage --- src/eval/mod.rs | 2 +- src/eval/ops.rs | 4 ++-- src/eval/scope.rs | 4 ++-- src/eval/str.rs | 6 +++--- src/eval/symbol.rs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/eval') diff --git a/src/eval/mod.rs b/src/eval/mod.rs index fe11606a..93a73ea4 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -256,7 +256,7 @@ impl<'a> Vm<'a> { } } - Err("cannot access file system from here".into()) + bail!("cannot access file system from here") } } diff --git a/src/eval/ops.rs b/src/eval/ops.rs index bea2ea82..0880a87e 100644 --- a/src/eval/ops.rs +++ b/src/eval/ops.rs @@ -6,7 +6,7 @@ use std::fmt::Debug; use ecow::eco_format; use super::{format_str, Regex, Value}; -use crate::diag::StrResult; +use crate::diag::{bail, StrResult}; use crate::geom::{Axes, Axis, GenAlign, Length, Numeric, PartialStroke, Rel, Smart}; use Value::*; @@ -219,7 +219,7 @@ pub fn mul(lhs: Value, rhs: Value) -> StrResult { /// Compute the quotient of two values. pub fn div(lhs: Value, rhs: Value) -> StrResult { if is_zero(&rhs) { - Err("cannot divide by zero")?; + bail!("cannot divide by zero"); } Ok(match (lhs, rhs) { diff --git a/src/eval/scope.rs b/src/eval/scope.rs index f2aa26fb..f3e13715 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -5,7 +5,7 @@ use std::hash::Hash; use ecow::{eco_format, EcoString}; use super::{IntoValue, Library, Value}; -use crate::diag::StrResult; +use crate::diag::{bail, StrResult}; /// A stack of scopes. #[derive(Debug, Default, Clone)] @@ -171,7 +171,7 @@ impl Slot { match self.kind { Kind::Normal => Ok(&mut self.value), Kind::Captured => { - Err("variables from outside the function are read-only and cannot be modified")? + bail!("variables from outside the function are read-only and cannot be modified") } } } diff --git a/src/eval/str.rs b/src/eval/str.rs index e3e83f3a..f5e5ab00 100644 --- a/src/eval/str.rs +++ b/src/eval/str.rs @@ -7,7 +7,7 @@ use ecow::EcoString; use unicode_segmentation::UnicodeSegmentation; use super::{cast, dict, Args, Array, Dict, Func, IntoValue, Value, Vm}; -use crate::diag::{At, SourceResult, StrResult}; +use crate::diag::{bail, At, SourceResult, StrResult}; use crate::geom::GenAlign; /// Create a new [`Str`] from a format string. @@ -507,7 +507,7 @@ cast! { let mut chars = string.chars(); match (chars.next(), chars.next()) { (Some(c), None) => c, - _ => Err("expected exactly one character")?, + _ => bail!("expected exactly one character"), } }, } @@ -600,7 +600,7 @@ cast! { align: GenAlign => match align { GenAlign::Start => Self::Start, GenAlign::End => Self::End, - _ => Err("expected either `start` or `end`")?, + _ => bail!("expected either `start` or `end`"), }, } diff --git a/src/eval/symbol.rs b/src/eval/symbol.rs index 8f4c93f8..0925202e 100644 --- a/src/eval/symbol.rs +++ b/src/eval/symbol.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use ecow::EcoString; -use crate::diag::StrResult; +use crate::diag::{bail, StrResult}; /// A symbol, possibly with variants. #[derive(Clone, Eq, PartialEq, Hash)] @@ -72,7 +72,7 @@ impl Symbol { } } - Err("unknown symbol modifier".into()) + bail!("unknown symbol modifier") } /// The characters that are covered by this symbol. -- cgit v1.2.3