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.
This commit is contained in:
Marcel Müller 2022-05-06 08:09:12 +02:00
parent 8ba24da443
commit 3914726ddb
1 changed files with 4 additions and 2 deletions

View File

@ -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())
}
})
}