diff --git a/src/diagnostic_impls.rs b/src/diagnostic_impls.rs new file mode 100644 index 0000000..aebe56b --- /dev/null +++ b/src/diagnostic_impls.rs @@ -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> { + match *self {} + } + + fn severity(&self) -> Option { + match *self {} + } + + fn help<'a>(&'a self) -> Option> { + match *self {} + } + + fn url<'a>(&'a self) -> Option> { + match *self {} + } + + fn source_code(&self) -> Option<&dyn SourceCode> { + match *self {} + } + + fn labels(&self) -> Option + '_>> { + match *self {} + } + + fn related<'a>(&'a self) -> Option + '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::; + } +} diff --git a/src/lib.rs b/src/lib.rs index 295dfcb..3c1a6fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -788,6 +788,7 @@ pub use protocol::*; mod chain; mod diagnostic_chain; +mod diagnostic_impls; mod error; mod eyreish; #[cfg(feature = "fancy-base")]