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 417647574d
1 changed files with 2 additions and 2 deletions

View File

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