From 417647574d7c9339ff739ee21cdd980de5ddde7e 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miette-derive/src/diagnostic_source.rs b/miette-derive/src/diagnostic_source.rs index 949defe..46a8a64 100644 --- a/miette-derive/src/diagnostic_source.rs +++ b/miette-derive/src/diagnostic_source.rs @@ -59,7 +59,7 @@ impl DiagnosticSource { }; quote! { Self::#ident #display_pat => { - std::option::Option::Some(#rel.as_ref()) + std::option::Option::Some(std::borrow::Borrow::borrow(#rel)) } } }) @@ -71,7 +71,7 @@ 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) + std::option::Option::Some(std::borrow::Borrow::borrow(&self.#rel)) } }) }