summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-12 16:43:49 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-12 16:47:46 +0200
commitd3b4d7da9a801dac3af6a3cf52eb55af83adc5f5 (patch)
tree72ab79ed75dddfb7b97ddf02ba4d19c4efc9ea5a /src/eval
parent378ebe5f5601f11c3f428c17bed492012feb251e (diff)
More `bail!` usage
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/mod.rs2
-rw-r--r--src/eval/ops.rs4
-rw-r--r--src/eval/scope.rs4
-rw-r--r--src/eval/str.rs6
-rw-r--r--src/eval/symbol.rs4
5 files changed, 10 insertions, 10 deletions
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<Value> {
/// Compute the quotient of two values.
pub fn div(lhs: Value, rhs: Value) -> StrResult<Value> {
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.