diff options
| author | David Wood <david.wood@huawei.com> | 2022-08-30 17:00:20 +0100 |
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2023-01-30 17:11:34 +0000 |
| commit | f7b42102e68537c6b0bbb3a1e83c9db69820dfb3 (patch) | |
| tree | 4d68aca42bfbb5355e5a37ef9448e414cc549bed | |
| parent | 59cc5e5d59796f5817d46b31450923597d9f8ae7 (diff) | |
| download | rust-f7b42102e68537c6b0bbb3a1e83c9db69820dfb3.tar.gz rust-f7b42102e68537c6b0bbb3a1e83c9db69820dfb3.zip | |
errors: implement `IntoDiagnosticArg` for `&T`
Implement `IntoDiagnosticArg` for `&'a T` when `T` implements `IntoDiagnosticArg` and `Clone`. Makes it easier to write diagnostic structs that borrow something which implements `IntoDiagnosticArg`. Signed-off-by: David Wood <david.wood@huawei.com>
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/region_name.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_borrowck/src/session_diagnostics.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic_impls.rs | 6 |
3 files changed, 13 insertions, 13 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 9233287cf3a..2440f20502a 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -187,6 +187,12 @@ impl Display for RegionName { } } +impl rustc_errors::IntoDiagnosticArg for RegionName { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + self.to_string().into_diagnostic_arg() + } +} + impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { pub(crate) fn mir_def_id(&self) -> hir::def_id::LocalDefId { self.body.source.def_id().expect_local() diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 23acf159240..13199d03852 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,4 +1,4 @@ -use rustc_errors::{IntoDiagnosticArg, MultiSpan}; +use rustc_errors::MultiSpan; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{GenericArg, Ty}; use rustc_span::Span; @@ -128,18 +128,6 @@ pub(crate) enum LifetimeReturnCategoryErr<'a> { }, } -impl IntoDiagnosticArg for &RegionName { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { - format!("{}", self).into_diagnostic_arg() - } -} - -impl IntoDiagnosticArg for RegionName { - fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { - format!("{}", self).into_diagnostic_arg() - } -} - #[derive(Subdiagnostic)] pub(crate) enum RequireStaticErr { #[note(borrowck_used_impl_require_static)] diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index dad5e98aac0..d5a5ef3b445 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -36,6 +36,12 @@ impl<'a, T: fmt::Display> From<&'a T> for DiagnosticArgFromDisplay<'a> { } } +impl<'a, T: Clone + IntoDiagnosticArg> IntoDiagnosticArg for &'a T { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + self.clone().into_diagnostic_arg() + } +} + macro_rules! into_diagnostic_arg_using_display { ($( $ty:ty ),+ $(,)?) => { $( |
