Skip to content

Commit 0d80ee7

Browse files
davidtwcoSkiFire13
authored andcommitted
errors: IntoDiagnosticArg for io::Error/paths
Add impls of `IntoDiagnosticArg` for `std::io::Error`, `std::path::Path` and `std::path::PathBuf`. Signed-off-by: David Wood <[email protected]>
1 parent 217a11b commit 0d80ee7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler/rustc_errors/src/diagnostic.rs

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_span::{edition::Edition, Span, DUMMY_SP};
1313
use std::borrow::Cow;
1414
use std::fmt;
1515
use std::hash::{Hash, Hasher};
16+
use std::path::{Path, PathBuf};
1617

1718
/// Error type for `Diagnostic`'s `suggestions` field, indicating that
1819
/// `.disable_suggestions()` was called on the `Diagnostic`.
@@ -83,6 +84,7 @@ into_diagnostic_arg_using_display!(
8384
u64,
8485
i128,
8586
u128,
87+
std::io::Error,
8688
std::num::NonZeroU32,
8789
hir::Target,
8890
Edition,
@@ -124,6 +126,18 @@ impl IntoDiagnosticArg for String {
124126
}
125127
}
126128

129+
impl<'a> IntoDiagnosticArg for &'a Path {
130+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
131+
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
132+
}
133+
}
134+
135+
impl IntoDiagnosticArg for PathBuf {
136+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
137+
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
138+
}
139+
}
140+
127141
impl IntoDiagnosticArg for usize {
128142
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
129143
DiagnosticArgValue::Number(self)

0 commit comments

Comments
 (0)