Repository: typst/typst
File: tests/src/run.rs (Rust)

Code before:
    /// Evaluate document content, this is the target agnostic part of compilation.
    fn eval(&mut self) -> Warned<SourceResult<Content>> {
        let evaluated = eval::eval(&self.world);

        let Warned { output, warnings } = &evaluated;
        for warning in warnings {
            self.check_diagnostic(NoteKind::Warning, warning, TestEval);
        }

        if let Err(errors) = output {
            for error in errors.iter() {
                self.check_diagnostic(NoteKind::Error, error, TestEval);
            }
        }

        evaluated
    }

    /// Compile a document with the specified target.
    fn compile<D: TestDocument>(
        &mut self,
        evaluated: Warned<SourceResult<Content>>,
    ) -> Option<D> {
        let Warned { output, warnings } = typst::compile::<D>(&self.world);

        // Conecptually this functions takes the evaluated content as input and
        // produces a document. In practice it also re-evaluates the sources and
        // thus generates duplicate diagnostics for the eval stage, so we filter
        // those out.

        let warnings = eval::deduplicate_with(warnings, &evaluated.warnings);
        for warning in warnings.iter() {
            self.check_diagnostic(NoteKind::Warning, warning, D::TARGET);
        }

        match output {
            Ok(output) => Some(output),
            Err(errors) => {
                let eval_errors = (evaluated.output.as_ref().err())
                    .map(|errors| errors.as_slice())
                    .unwrap_or(&[]);
                let errors = eval::deduplicate_with(errors, eval_errors);

                for error in errors.iter() {
                    self.check_diagnostic(NoteKind::Error, error, D::TARGET);
                }

                None
            }
        }
    }

Review comment (suggestion):
```suggestion
        // Conceptually this functions takes the evaluated content as input and
```

Code after:
    /// Evaluate document content, this is the target agnostic part of compilation.
    fn eval(&mut self) -> Warned<SourceResult<Content>> {
        let evaluated = eval::eval(&self.world);

        let Warned { output, warnings } = &evaluated;
        for warning in warnings {
            self.check_diagnostic(NoteKind::Warning, warning, TestEval);
        }

        if let Err(errors) = output {
            for error in errors.iter() {
                self.check_diagnostic(NoteKind::Error, error, TestEval);
            }
        }

        evaluated
    }

    /// Compile a document with the specified target.
    ///
    /// Conceptually, this functions takes the evaluated content as input and
    /// produces a document. In practice it also re-evaluates the sources and
    /// thus generates duplicate diagnostics for the eval stage, so we filter
    /// those out.
    fn compile<D: TestDocument>(
        &mut self,
        evaluated: Warned<SourceResult<Content>>,
    ) -> Option<D> {
        let Warned { output, warnings } = typst::compile::<D>(&self.world);

        let warnings = eval::deduplicate_with(warnings, &evaluated.warnings);
        for warning in warnings.iter() {
            self.check_diagnostic(NoteKind::Warning, warning, D::TARGET);
        }

        match output {
            Ok(output) => Some(output),
            Err(errors) => {
                let eval_errors = (evaluated.output.as_ref().err())
                    .map(|errors| errors.as_slice())
                    .unwrap_or(&[]);
                let errors = eval::deduplicate_with(errors, eval_errors);

                for error in errors.iter() {
                    self.check_diagnostic(NoteKind::Error, error, D::TARGET);
                }

                None
            }
        }
    }