|
2 | 2 | Default trait implementations for [`Diagnostic`].
|
3 | 3 | */
|
4 | 4 |
|
5 |
| -use std::{convert::Infallible, fmt::Display, hint::unreachable_unchecked}; |
| 5 | +use std::{convert::Infallible, fmt::Display}; |
6 | 6 |
|
7 | 7 | use crate::{Diagnostic, LabeledSpan, Severity, SourceCode};
|
8 | 8 |
|
9 |
| -// Since all trait methods for [`Diagnostic`] take a reference to `self`, there must be an instance of `Self`. |
10 |
| -// However, since an instance of [`Infallible`] can never be constructed, these methods can never be called. |
11 |
| -// Therefore, these methods are unreachable, and can be safely optimized away by the compiler. |
12 |
| -#[allow(clippy::undocumented_unsafe_blocks)] |
13 | 9 | impl Diagnostic for Infallible {
|
14 | 10 | fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
15 |
| - unsafe { unreachable_unchecked() } |
| 11 | + match *self {} |
16 | 12 | }
|
17 | 13 |
|
18 | 14 | fn severity(&self) -> Option<Severity> {
|
19 |
| - unsafe { unreachable_unchecked() } |
| 15 | + match *self {} |
20 | 16 | }
|
21 | 17 |
|
22 | 18 | fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
23 |
| - unsafe { unreachable_unchecked() } |
| 19 | + match *self {} |
24 | 20 | }
|
25 | 21 |
|
26 | 22 | fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
|
27 |
| - unsafe { unreachable_unchecked() } |
| 23 | + match *self {} |
28 | 24 | }
|
29 | 25 |
|
30 | 26 | fn source_code(&self) -> Option<&dyn SourceCode> {
|
31 |
| - unsafe { unreachable_unchecked() } |
| 27 | + match *self {} |
32 | 28 | }
|
33 | 29 |
|
34 | 30 | fn labels(&self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + '_>> {
|
35 |
| - unsafe { unreachable_unchecked() } |
| 31 | + match *self {} |
36 | 32 | }
|
37 | 33 |
|
38 | 34 | fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
39 |
| - unsafe { unreachable_unchecked() } |
| 35 | + match *self {} |
40 | 36 | }
|
41 | 37 |
|
42 | 38 | fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
|
43 |
| - unsafe { unreachable_unchecked() } |
| 39 | + match *self {} |
44 | 40 | }
|
45 | 41 | }
|
46 | 42 |
|
|
0 commit comments