From f7b42102e68537c6b0bbb3a1e83c9db69820dfb3 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 30 Aug 2022 17:00:20 +0100 Subject: 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 --- compiler/rustc_errors/src/diagnostic_impls.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'compiler/rustc_errors/src') 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 ),+ $(,)?) => { $( -- cgit 1.4.1-3-g733a5