1
Fork 0

Remove some direct calls to local_def_id_to_hir_id on diagnostics

This commit is contained in:
Santiago Pastorino 2023-03-08 23:42:08 -03:00
parent 669e751639
commit 4824363e67
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
2 changed files with 6 additions and 2 deletions

View file

@ -316,7 +316,7 @@ impl<'hir> Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
#[inline] #[inline]
pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>> { pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>> {
self.find(self.local_def_id_to_hir_id(id)) self.find(self.tcx.opt_local_def_id_to_hir_id(id)?)
} }
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
@ -333,7 +333,7 @@ impl<'hir> Map<'hir> {
} }
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> { pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> {
id.as_local().and_then(|id| self.find(self.local_def_id_to_hir_id(id))) id.as_local().and_then(|id| self.find(self.tcx.opt_local_def_id_to_hir_id(id)?))
} }
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> { pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> {

View file

@ -144,6 +144,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
trait_ref: ty::PolyTraitRef<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
) -> OnUnimplementedNote { ) -> OnUnimplementedNote {
if self.tcx.opt_rpitit_info(obligation.cause.body_id.to_def_id()).is_some() {
return OnUnimplementedNote::default();
}
let (def_id, substs) = self let (def_id, substs) = self
.impl_similar_to(trait_ref, obligation) .impl_similar_to(trait_ref, obligation)
.unwrap_or_else(|| (trait_ref.def_id(), trait_ref.skip_binder().substs)); .unwrap_or_else(|| (trait_ref.def_id(), trait_ref.skip_binder().substs));