Skip to content

Commit

Permalink
feat(protocol): help is a single Display ref now.
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 8, 2021
1 parent 7920a23 commit 80e7dab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn '_ + Iterator<Item = &'_ str>>> {
fn help(&self) -> Option<&(dyn Display)> {
None
}

Expand Down
9 changes: 2 additions & 7 deletions src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down Expand Up @@ -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::<Vec<&str>>()
.join(" ")
.unwrap_or(&"have you tried not failing?")
)?;
writeln!(
f,
Expand Down
6 changes: 2 additions & 4 deletions tests/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ impl Diagnostic for MyBad {
&"oops::my::bad"
}

}

fn help(&self) -> Option<Box<dyn '_ + Iterator<Item = &'_ str>>> {
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]> {
Expand Down

0 comments on commit 80e7dab

Please sign in to comment.