From 7fcc18daea448b209c415f3abc661d56f4854b1d Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 22 Aug 2022 18:38:55 +0900 Subject: [PATCH] integrate CodegenError to compiler-core::Error --- core/src/error.rs | 20 ++++++++++++++++++++ parser/src/error.rs | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/src/error.rs b/core/src/error.rs index 4553b60..d249755 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use crate::Location; #[derive(Debug, PartialEq, Eq)] @@ -15,6 +17,24 @@ impl std::ops::Deref for Error { } } +impl std::error::Error for Error +where + T: std::fmt::Display + std::fmt::Debug, +{ + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + None + } +} + +impl Display for Error +where + T: std::fmt::Display, +{ + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + self.location.fmt_with(f, &self.error) + } +} + impl Error { pub fn error(self) -> T { self.error diff --git a/parser/src/error.rs b/parser/src/error.rs index b64abcb..257d4c6 100644 --- a/parser/src/error.rs +++ b/parser/src/error.rs @@ -193,7 +193,7 @@ impl ParseError { impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.location.fmt_with(f, &self.error) + self.0.fmt(f) } }