From 3914726ddb385b7fb7be2356b9f1244f790be3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 6 May 2022 08:09:12 +0200 Subject: [PATCH] Use Borrow::borrow instead of AsRef AsRef is not reflexive, meaning that it is not implemented as &T for all T. Borrow is though, so we use that to make sure that we always get a reference that is correct, even in the presence of smart pointers. --- miette-derive/src/diagnostic_source.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/miette-derive/src/diagnostic_source.rs b/miette-derive/src/diagnostic_source.rs index 949defe..d423aaa 100644 --- a/miette-derive/src/diagnostic_source.rs +++ b/miette-derive/src/diagnostic_source.rs @@ -59,7 +59,8 @@ impl DiagnosticSource { }; quote! { Self::#ident #display_pat => { - std::option::Option::Some(#rel.as_ref()) + use std::borrow::Borrow; + std::option::Option::Some(#rel.borrow()) } } }) @@ -71,7 +72,8 @@ impl DiagnosticSource { let rel = &self.0; Some(quote! { fn diagnostic_source<'a>(&'a self) -> std::option::Option<&'a dyn miette::Diagnostic> { - std::option::Option::Some(&self.#rel) + use std::borrow::Borrow; + std::option::Option::Some(self.#rel.borrow()) } }) }