Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Diagnostic for Infallible #402

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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