Skip to content

Commit

Permalink
feat(Diagnostic): Implement Diagnostic for Infallible (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
caass authored Sep 25, 2024
1 parent d60c8f1 commit f3fb4c1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*!
Default trait implementations for [`Diagnostic`].
*/

use std::{convert::Infallible, fmt::Display};

use crate::{Diagnostic, LabeledSpan, Severity, SourceCode};

impl Diagnostic for Infallible {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
match *self {}
}

fn severity(&self) -> Option<Severity> {
match *self {}
}

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
match *self {}
}

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
match *self {}
}

fn source_code(&self) -> Option<&dyn SourceCode> {
match *self {}
}

fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
match *self {}
}

fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
match *self {}
}

fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
match *self {}
}
}

#[cfg(test)]
mod tests {
use super::*;

use crate::Report;

/// Test that [`Infallible`] implements [`Diagnostic`] by seeing if a function that's generic over `Diagnostic`
/// will accept `Infallible` as a type parameter.
#[test]
fn infallible() {
let _ = Report::new::<Infallible>;
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ pub use protocol::*;

mod chain;
mod diagnostic_chain;
mod diagnostic_impls;
mod error;
mod eyreish;
#[cfg(feature = "fancy-base")]
Expand Down

0 comments on commit f3fb4c1

Please sign in to comment.