diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst/src/eval/access.rs | 2 | ||||
| -rw-r--r-- | crates/typst/src/foundations/array.rs | 2 | ||||
| -rw-r--r-- | crates/typst/src/foundations/cast.rs | 8 | ||||
| -rw-r--r-- | crates/typst/src/foundations/dict.rs | 9 |
4 files changed, 14 insertions, 7 deletions
diff --git a/crates/typst/src/eval/access.rs b/crates/typst/src/eval/access.rs index 99b2f72e..e3bf2bf0 100644 --- a/crates/typst/src/eval/access.rs +++ b/crates/typst/src/eval/access.rs @@ -7,7 +7,7 @@ use crate::syntax::ast::{self, AstNode}; /// Access an expression mutably. pub(crate) trait Access { - /// Access the value. + /// Access the expression's evaluated value mutably. fn access<'a>(self, vm: &'a mut Vm) -> SourceResult<&'a mut Value>; } diff --git a/crates/typst/src/foundations/array.rs b/crates/typst/src/foundations/array.rs index 6f7c6347..27f56194 100644 --- a/crates/typst/src/foundations/array.rs +++ b/crates/typst/src/foundations/array.rs @@ -113,7 +113,7 @@ impl Array { let len = self.len(); self.locate_opt(index, false) .and_then(move |i| self.0.make_mut().get_mut(i)) - .ok_or_else(|| out_of_bounds_no_default(index, len)) + .ok_or_else(|| out_of_bounds(index, len)) } /// Resolve an index or throw an out of bounds error. diff --git a/crates/typst/src/foundations/cast.rs b/crates/typst/src/foundations/cast.rs index 6a40cecc..716eae9d 100644 --- a/crates/typst/src/foundations/cast.rs +++ b/crates/typst/src/foundations/cast.rs @@ -8,7 +8,7 @@ use ecow::{eco_format, EcoString}; use smallvec::SmallVec; use unicode_math_class::MathClass; -use crate::diag::{At, SourceResult, StrResult}; +use crate::diag::{At, HintedStrResult, SourceResult, StrResult}; use crate::foundations::{array, repr, NativeElement, Packed, Repr, Str, Type, Value}; use crate::syntax::{Span, Spanned}; @@ -233,6 +233,12 @@ impl<T: IntoValue> IntoResult for StrResult<T> { } } +impl<T: IntoValue> IntoResult for HintedStrResult<T> { + fn into_result(self, span: Span) -> SourceResult<Value> { + self.map(IntoValue::into_value).at(span) + } +} + impl<T: IntoValue> IntoResult for SourceResult<T> { fn into_result(self, _: Span) -> SourceResult<Value> { self.map(IntoValue::into_value) diff --git a/crates/typst/src/foundations/dict.rs b/crates/typst/src/foundations/dict.rs index 341504cb..59dd85c7 100644 --- a/crates/typst/src/foundations/dict.rs +++ b/crates/typst/src/foundations/dict.rs @@ -7,7 +7,7 @@ use ecow::{eco_format, EcoString}; use indexmap::IndexMap; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use crate::diag::StrResult; +use crate::diag::{Hint, HintedStrResult, StrResult}; use crate::foundations::{array, func, repr, scope, ty, Array, Repr, Str, Value}; use crate::syntax::is_ident; use crate::util::ArcExt; @@ -83,10 +83,11 @@ impl Dict { } /// Mutably borrow the value the given `key` maps to. - pub fn at_mut(&mut self, key: &str) -> StrResult<&mut Value> { + pub fn at_mut(&mut self, key: &str) -> HintedStrResult<&mut Value> { Arc::make_mut(&mut self.0) .get_mut(key) - .ok_or_else(|| missing_key_no_default(key)) + .ok_or_else(|| missing_key(key)) + .hint("use `insert` to add or update values") } /// Remove the value if the dictionary contains the given key. @@ -354,7 +355,7 @@ fn missing_key(key: &str) -> EcoString { eco_format!("dictionary does not contain key {}", key.repr()) } -/// The missing key access error message when no default was fiven. +/// The missing key access error message when no default was given. #[cold] fn missing_key_no_default(key: &str) -> EcoString { eco_format!( |
