diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs index dd5deab2a..9b73dd7f0 100644 --- a/crates/typst-syntax/src/node.rs +++ b/crates/typst-syntax/src/node.rs @@ -3,7 +3,7 @@ use std::ops::{Deref, Range}; use std::rc::Rc; use std::sync::Arc; -use ecow::EcoString; +use ecow::{eco_vec, EcoString, EcoVec}; use super::ast::AstNode; use super::{FileId, Span, SyntaxKind}; @@ -616,7 +616,7 @@ impl ErrorNode { error: SyntaxError { span: Span::detached(), message: message.into(), - hints: vec![], + hints: eco_vec![], }, } } @@ -652,7 +652,7 @@ pub struct SyntaxError { pub message: EcoString, /// Additonal hints to the user, indicating how this error could be avoided /// or worked around. - pub hints: Vec, + pub hints: EcoVec, } impl SyntaxError { diff --git a/crates/typst/src/diag.rs b/crates/typst/src/diag.rs index 846ab78f1..9342606ec 100644 --- a/crates/typst/src/diag.rs +++ b/crates/typst/src/diag.rs @@ -7,6 +7,7 @@ use std::str::Utf8Error; use std::string::FromUtf8Error; use comemo::Tracked; +use ecow::{eco_vec, EcoVec}; use crate::syntax::{PackageSpec, Span, Spanned, SyntaxError}; use crate::{World, WorldExt}; @@ -29,14 +30,14 @@ macro_rules! __bail { }; ($error:expr) => { - return Err(Box::new(vec![$error])) + return Err(::ecow::eco_vec![$error]) }; ($span:expr, $fmt:literal $(, $arg:expr)* $(,)?) => { - return Err(Box::new(vec![$crate::diag::SourceDiagnostic::error( + return Err(::ecow::eco_vec![$crate::diag::SourceDiagnostic::error( $span, $crate::diag::eco_format!($fmt, $($arg),*), - )])) + )]) }; } @@ -75,7 +76,7 @@ macro_rules! __warning { } /// A result that can carry multiple source errors. -pub type SourceResult = Result>>; +pub type SourceResult = Result>; /// An error or warning in a source file. /// @@ -90,10 +91,10 @@ pub struct SourceDiagnostic { /// A diagnostic message describing the problem. pub message: EcoString, /// The trace of function calls leading to the problem. - pub trace: Vec>, + pub trace: EcoVec>, /// Additonal hints to the user, indicating how this problem could be avoided /// or worked around. - pub hints: Vec, + pub hints: EcoVec, } /// The severity of a [`SourceDiagnostic`]. @@ -111,9 +112,9 @@ impl SourceDiagnostic { Self { severity: Severity::Error, span, - trace: vec![], + trace: eco_vec![], message: message.into(), - hints: vec![], + hints: eco_vec![], } } @@ -122,9 +123,9 @@ impl SourceDiagnostic { Self { severity: Severity::Warning, span, - trace: vec![], + trace: eco_vec![], message: message.into(), - hints: vec![], + hints: eco_vec![], } } @@ -152,7 +153,7 @@ impl From for SourceDiagnostic { severity: Severity::Error, span: error.span, message: error.message, - trace: vec![], + trace: eco_vec![], hints: error.hints, } } @@ -203,7 +204,7 @@ impl Trace for SourceResult { { self.map_err(|mut errors| { let Some(trace_range) = world.range(span) else { return errors }; - for error in errors.iter_mut() { + for error in errors.make_mut().iter_mut() { // Skip traces that surround the error. if let Some(error_range) = world.range(error.span) { if error.span.id() == span.id() @@ -242,7 +243,7 @@ where diagnostic .hint("you can adjust the project root with the --root argument"); } - Box::new(vec![diagnostic]) + eco_vec![diagnostic] }) } } @@ -263,9 +264,7 @@ pub struct HintedString { impl At for Result { fn at(self, span: Span) -> SourceResult { self.map_err(|diags| { - Box::new(vec![ - SourceDiagnostic::error(span, diags.message).with_hints(diags.hints) - ]) + eco_vec![SourceDiagnostic::error(span, diags.message).with_hints(diags.hints)] }) } } diff --git a/crates/typst/src/eval/args.rs b/crates/typst/src/eval/args.rs index aad9fda6a..c347f5277 100644 --- a/crates/typst/src/eval/args.rs +++ b/crates/typst/src/eval/args.rs @@ -1,6 +1,6 @@ use std::fmt::{self, Debug, Formatter}; -use ecow::{eco_format, EcoString, EcoVec}; +use ecow::{eco_format, eco_vec, EcoString, EcoVec}; use super::{func, scope, ty, Array, Dict, FromValue, IntoValue, Repr, Str, Value}; use crate::diag::{bail, At, SourceDiagnostic, SourceResult}; @@ -155,7 +155,7 @@ impl Args { T: FromValue>, { let mut list = vec![]; - let mut errors = vec![]; + let mut errors = eco_vec![]; self.items.retain(|item| { if item.name.is_some() { return true; @@ -169,7 +169,7 @@ impl Args { false }); if !errors.is_empty() { - return Err(Box::new(errors)); + return Err(errors); } Ok(list) } diff --git a/crates/typst/src/eval/mod.rs b/crates/typst/src/eval/mod.rs index b6dbace9f..b527bed1e 100644 --- a/crates/typst/src/eval/mod.rs +++ b/crates/typst/src/eval/mod.rs @@ -134,7 +134,7 @@ pub fn eval( let root = source.root(); let errors = root.errors(); if !errors.is_empty() && vm.inspected.is_none() { - return Err(Box::new(errors.into_iter().map(Into::into).collect())); + return Err(errors.into_iter().map(Into::into).collect()); } // Evaluate the module. @@ -178,7 +178,7 @@ pub fn eval_string( let errors = root.errors(); if !errors.is_empty() { - return Err(Box::new(errors.into_iter().map(Into::into).collect())); + return Err(errors.into_iter().map(Into::into).collect()); } // Prepare VT. @@ -1786,7 +1786,7 @@ impl Eval for ast::ModuleImport<'_> { } } Some(ast::Imports::Items(items)) => { - let mut errors = vec![]; + let mut errors = eco_vec![]; for item in items.iter() { let original_ident = item.original_name(); if let Some(value) = scope.get(&original_ident) { @@ -1808,7 +1808,7 @@ impl Eval for ast::ModuleImport<'_> { } } if !errors.is_empty() { - return Err(Box::new(errors)); + return Err(errors); } } } diff --git a/crates/typst/src/model/mod.rs b/crates/typst/src/model/mod.rs index 2741f7316..dcad87419 100644 --- a/crates/typst/src/model/mod.rs +++ b/crates/typst/src/model/mod.rs @@ -8,6 +8,7 @@ mod realize; mod selector; mod styles; +use ecow::EcoVec; #[doc(inline)] pub use typst_macros::elem; @@ -89,7 +90,7 @@ pub fn typeset( // Promote delayed errors. if !delayed.0.is_empty() { - return Err(Box::new(delayed.0)); + return Err(delayed.0); } Ok(document) @@ -123,7 +124,7 @@ impl Vt<'_> { match f(self) { Ok(value) => value, Err(errors) => { - for error in *errors { + for error in errors { self.delayed.push(error); } T::default() @@ -134,7 +135,7 @@ impl Vt<'_> { /// Holds delayed errors. #[derive(Default, Clone)] -pub struct DelayedErrors(Vec); +pub struct DelayedErrors(EcoVec); impl DelayedErrors { /// Create an empty list of delayed errors. diff --git a/tests/src/tests.rs b/tests/src/tests.rs index 41fd00e86..bdbfd3979 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -545,7 +545,7 @@ fn test_part( Ok(document) => (document.pages, tracer.warnings()), Err(errors) => { let mut warnings = tracer.warnings(); - warnings.extend(*errors); + warnings.extend(errors); (vec![], warnings) } };