Skip to content

Commit

Permalink
Use Borrow::borrow instead of AsRef
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheNeikos committed May 6, 2022
1 parent 8ba24da commit 3914726
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions miette-derive/src/diagnostic_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
})
Expand All @@ -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())
}
})
}
Expand Down

0 comments on commit 3914726

Please sign in to comment.