From 80e7dabbe450d4a78ed18174e2a383a6a1ed0557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Sat, 7 Aug 2021 22:57:56 -0400 Subject: [PATCH] feat(protocol): help is a single Display ref now. --- src/protocol.rs | 2 +- src/reporter.rs | 9 ++------- tests/reporter.rs | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/protocol.rs b/src/protocol.rs index a4e5f40..2c192f1 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -30,7 +30,7 @@ pub trait Diagnostic: std::error::Error { /// Additional help text related to this Diagnostic. Do you have any /// advice for the poor soul who's just run into this issue? - fn help(&self) -> Option>> { + fn help(&self) -> Option<&(dyn Display)> { None } diff --git a/src/reporter.rs b/src/reporter.rs index 1224bc5..bcebf9e 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -131,10 +131,7 @@ impl DiagnosticReporter for MietteReporter { } if let Some(help) = diagnostic.help() { - writeln!(f)?; - for msg in help { - writeln!(f, "﹦{}", msg)?; - } + writeln!(f, "﹦{}", help)?; } Ok(()) @@ -162,9 +159,7 @@ impl DiagnosticReporter for JokeReporter { diagnostic, diagnostic .help() - .unwrap_or_else(|| Box::new(vec!["have you tried not failing?"].into_iter())) - .collect::>() - .join(" ") + .unwrap_or(&"have you tried not failing?") )?; writeln!( f, diff --git a/tests/reporter.rs b/tests/reporter.rs index 2b36dab..7fa2653 100644 --- a/tests/reporter.rs +++ b/tests/reporter.rs @@ -23,10 +23,8 @@ impl Diagnostic for MyBad { &"oops::my::bad" } - } - - fn help(&self) -> Option>> { - Some(Box::new(vec!["try doing it better next time?"].into_iter())) + fn help(&self) -> Option<&(dyn std::fmt::Display)> { + Some(&"try doing it better next time?") } fn snippets(&self) -> Option<&[DiagnosticSnippet]> {