Skip to content

Commit

Permalink
errors: IntoDiagnosticArg for io::Error/paths
Browse files Browse the repository at this point in the history
Add impls of `IntoDiagnosticArg` for `std::io::Error`, `std::path::Path`
and `std::path::PathBuf`.

Signed-off-by: David Wood <david.wood@huawei.com>
  • Loading branch information
davidtwco authored and wonchulee committed Aug 23, 2022
1 parent 9b95eef commit c18503f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -83,6 +84,7 @@ into_diagnostic_arg_using_display!(
u64,
i128,
u128,
std::io::Error,
std::num::NonZeroU32,
hir::Target,
Edition,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c18503f

Please sign in to comment.