miette/
diagnostic_impls.rs

1/*!
2Default trait implementations for [`Diagnostic`].
3*/
4
5use std::{convert::Infallible, fmt::Display};
6
7use crate::{Diagnostic, LabeledSpan, Severity, SourceCode};
8
9impl Diagnostic for Infallible {
10    fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
11        match *self {}
12    }
13
14    fn severity(&self) -> Option<Severity> {
15        match *self {}
16    }
17
18    fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
19        match *self {}
20    }
21
22    fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
23        match *self {}
24    }
25
26    fn source_code(&self) -> Option<&dyn SourceCode> {
27        match *self {}
28    }
29
30    fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
31        match *self {}
32    }
33
34    fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
35        match *self {}
36    }
37
38    fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
39        match *self {}
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    use crate::Report;
48
49    /// Test that [`Infallible`] implements [`Diagnostic`] by seeing if a function that's generic over `Diagnostic`
50    /// will accept `Infallible` as a type parameter.
51    #[test]
52    fn infallible() {
53        let _ = Report::new::<Infallible>;
54    }
55}