about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorDavid Wood <david.wood@huawei.com>2022-08-19 14:45:54 +0100
committerWonchul Lee <wonchul.dev@gmail.com>2022-08-24 06:50:44 +0900
commitc18503f3ff9f81ed3b368246ade73e79dbd53282 (patch)
tree66b3e5a3832e8bc7f03cfda889412bbd57976fa8 /compiler/rustc_errors/src
parent9b95eef6ea3fc8a371241277698be881d4ec4bb7 (diff)
downloadrust-c18503f3ff9f81ed3b368246ade73e79dbd53282.tar.gz
rust-c18503f3ff9f81ed3b368246ade73e79dbd53282.zip
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 <david.wood@huawei.com>
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/diagnostic.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs
index 356f9dfdb3b..506198df4d8 100644
--- a/compiler/rustc_errors/src/diagnostic.rs
+++ b/compiler/rustc_errors/src/diagnostic.rs
@@ -13,6 +13,7 @@ use rustc_span::{edition::Edition, Span, DUMMY_SP};
 use std::borrow::Cow;
 use std::fmt;
 use std::hash::{Hash, Hasher};
+use std::path::{Path, PathBuf};
 
 /// Error type for `Diagnostic`'s `suggestions` field, indicating that
 /// `.disable_suggestions()` was called on the `Diagnostic`.
@@ -83,6 +84,7 @@ into_diagnostic_arg_using_display!(
     u64,
     i128,
     u128,
+    std::io::Error,
     std::num::NonZeroU32,
     hir::Target,
     Edition,
@@ -124,6 +126,18 @@ impl IntoDiagnosticArg for String {
     }
 }
 
+impl<'a> IntoDiagnosticArg for &'a Path {
+    fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+        DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
+    }
+}
+
+impl IntoDiagnosticArg for PathBuf {
+    fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+        DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))
+    }
+}
+
 impl IntoDiagnosticArg for usize {
     fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
         DiagnosticArgValue::Number(self)