From 78e4cd5dbcbc2c05337b6a77158367ec7b4bc1ea Mon Sep 17 00:00:00 2001 From: Mikko Lehtonen Date: Tue, 3 Aug 2021 01:20:16 +0300 Subject: [PATCH] Remove AsDisplay trait in error formatting --- wgpu-core/src/error.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/wgpu-core/src/error.rs b/wgpu-core/src/error.rs index 4b4b1fb6d2..fa023a94ae 100644 --- a/wgpu-core/src/error.rs +++ b/wgpu-core/src/error.rs @@ -6,23 +6,13 @@ use crate::{ hub::{Global, IdentityManagerFactory}, }; -pub trait AsDisplay { - fn as_display(&self) -> &dyn fmt::Display; -} - -impl AsDisplay for T { - fn as_display(&self) -> &dyn fmt::Display { - self - } -} - pub struct ErrorFormatter<'a> { writer: &'a mut dyn fmt::Write, global: &'a Global, } impl<'a> ErrorFormatter<'a> { - pub fn error(&mut self, err: &dyn fmt::Display) { + pub fn error(&mut self, err: &dyn Error) { writeln!(self.writer, " {}", err).expect("Error formatting error"); } @@ -103,9 +93,9 @@ impl<'a> ErrorFormatter<'a> { } } -pub trait PrettyError: Error { +pub trait PrettyError: Error + Sized { fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self.as_display()); + fmt.error(self); } } @@ -154,7 +144,7 @@ pub fn format_pretty_any( } // default - fmt.error(error.as_display()) + fmt.error(error) } #[derive(Debug)] @@ -167,7 +157,7 @@ pub struct ContextError { impl PrettyError for ContextError { fn fmt_pretty(&self, fmt: &mut ErrorFormatter) { - fmt.error(self.as_display()); + fmt.error(self); fmt.label(self.label_key, &self.label); } }