diff --git a/src/protocol.rs b/src/protocol.rs index ceebf6d..2a5f88c 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -18,7 +18,7 @@ pub trait Diagnostic: std::error::Error { /// the toplevel crate's documentation for easy searching. Rust path /// format (`foo::bar::baz`) is recommended, but more classic codes like /// `E0123` or Enums will work just fine. - fn code(&self) -> &(dyn Display); + fn code<'a>(&'a self) -> Box; /// Diagnostic severity. This may be used by [DiagnosticReporter]s to change the /// display format of this diagnostic. @@ -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<&(dyn Display)> { + fn help<'a>(&'a self) -> Option> { None } diff --git a/src/reporter.rs b/src/reporter.rs index 8a3454b..42177b4 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -163,7 +163,9 @@ impl DiagnosticReporter for JokeReporter { "me, with {} {}: {}", sev, diagnostic, - diagnostic.help().unwrap_or(&"have you tried not failing?") + diagnostic + .help() + .unwrap_or_else(|| Box::new(&"have you tried not failing?")) )?; writeln!( f, diff --git a/tests/reporter.rs b/tests/reporter.rs index b3aef01..b220530 100644 --- a/tests/reporter.rs +++ b/tests/reporter.rs @@ -18,12 +18,12 @@ impl fmt::Debug for MyBad { } impl Diagnostic for MyBad { - fn code(&self) -> &(dyn std::fmt::Display) { - &"oops::my::bad" + fn code(&self) -> Box { + Box::new(&"oops::my::bad") } - fn help(&self) -> Option<&(dyn std::fmt::Display)> { - Some(&"try doing it better next time?") + fn help(&self) -> Option> { + Some(Box::new(&"try doing it better next time?")) } fn snippets(&self) -> Option>> {