Skip to content

Commit

Permalink
return refs to simplifiable types in non_blanket_impls_for_ty
Browse files Browse the repository at this point in the history
for users of the API, we return impls from `non_blanket_impls` and `impls_for_ref_x` as if they
weren't separated.
  • Loading branch information
lqd committed May 31, 2023
1 parent f2b58f3 commit 030f9bb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions compiler/rustc_middle/src/ty/trait_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,24 @@ impl<'tcx> TyCtxt<'tcx> {
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
let impls = self.trait_impls_of(trait_def_id);
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
if let Some(impls) = impls.non_blanket_impls.get(&simp) {

// Non-blanket impls are grouped into two different maps:
// 1) impls for references to simplifiable types
if let TyKind::Ref(_, ref_ty, _) = self_ty.kind() {
if let Some(simplified_ref_ty) =
fast_reject::simplify_type(self, *ref_ty, TreatParams::AsCandidateKey)
{
if let Some(impls) = impls.impls_for_ref_x.get(&simplified_ref_ty) {
return impls.iter().copied();
}
}
}

// 2) the other non-blanket impls
if let Some(simplified_self_ty) =
fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey)
{
if let Some(impls) = impls.non_blanket_impls.get(&simplified_self_ty) {
return impls.iter().copied();
}
}
Expand Down

0 comments on commit 030f9bb

Please sign in to comment.