mirror of https://github.com/zkat/miette.git
fix(Diagnostic): remove usage of unsafe code from `Infallible` impl
This commit is contained in:
parent
a2bea9990e
commit
35d0f077c1
|
|
@ -2,45 +2,41 @@
|
||||||
Default trait implementations for [`Diagnostic`].
|
Default trait implementations for [`Diagnostic`].
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::{convert::Infallible, fmt::Display, hint::unreachable_unchecked};
|
use std::{convert::Infallible, fmt::Display};
|
||||||
|
|
||||||
use crate::{Diagnostic, LabeledSpan, Severity, SourceCode};
|
use crate::{Diagnostic, LabeledSpan, Severity, SourceCode};
|
||||||
|
|
||||||
// Since all trait methods for [`Diagnostic`] take a reference to `self`, there must be an instance of `Self`.
|
|
||||||
// However, since an instance of [`Infallible`] can never be constructed, these methods can never be called.
|
|
||||||
// Therefore, these methods are unreachable, and can be safely optimized away by the compiler.
|
|
||||||
#[allow(clippy::undocumented_unsafe_blocks)]
|
|
||||||
impl Diagnostic for Infallible {
|
impl Diagnostic for Infallible {
|
||||||
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn severity(&self) -> Option<Severity> {
|
fn severity(&self) -> Option<Severity> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn source_code(&self) -> Option<&dyn SourceCode> {
|
fn source_code(&self) -> Option<&dyn SourceCode> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
|
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
|
||||||
unsafe { unreachable_unchecked() }
|
match *self {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue