miette/
diagnostic_impls.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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>;
    }
}