From d8e2ece2246c579ccffe4abe946fc39603caeb80 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Thu, 17 Nov 2022 20:48:42 +0900 Subject: [PATCH] impl Display for ComileErrors --- compiler/erg_common/error.rs | 7 ------- compiler/erg_compiler/error.rs | 7 +++++++ compiler/erg_parser/error.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/erg_common/error.rs b/compiler/erg_common/error.rs index cc1e8670..fab1d2d5 100644 --- a/compiler/erg_common/error.rs +++ b/compiler/erg_common/error.rs @@ -810,11 +810,4 @@ pub trait MultiErrorDisplay: Stream { } write!(f, "") } - - fn write_all(&self, w: &mut W) { - let mut writer = BufWriter::new(w); - for err in self.iter() { - err.write_to(&mut writer); - } - } } diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index 179966bb..64f568c1 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::fmt::Display; use erg_common::astr::AtomicStr; @@ -1814,6 +1815,12 @@ impl From for CompileErrors { impl MultiErrorDisplay for CompileErrors {} +impl fmt::Display for CompileErrors { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_all(f) + } +} + impl CompileErrors { pub fn flush(&mut self) -> Self { Self(self.0.drain(..).collect()) diff --git a/compiler/erg_parser/error.rs b/compiler/erg_parser/error.rs index 95d63f01..90e5997e 100644 --- a/compiler/erg_parser/error.rs +++ b/compiler/erg_parser/error.rs @@ -1,6 +1,8 @@ //! defines `ParseError` and others. //! //! パーサーが出すエラーを定義 +use std::fmt; + use erg_common::astr::AtomicStr; use erg_common::config::Input; use erg_common::error::{ErrorCore, ErrorDisplay, ErrorKind::*, Location, MultiErrorDisplay}; @@ -200,6 +202,12 @@ impl_stream_for_wrapper!(ParserRunnerErrors, ParserRunnerError); impl MultiErrorDisplay for ParserRunnerErrors {} +impl fmt::Display for ParserRunnerErrors { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_all(f) + } +} + impl ParserRunnerErrors { pub fn convert(input: &Input, errs: ParseErrors, theme: Theme) -> Self { Self(