Skip to content

Commit 030f9bb

Browse files
committed
return refs to simplifiable types in non_blanket_impls_for_ty
for users of the API, we return impls from `non_blanket_impls` and `impls_for_ref_x` as if they weren't separated.
1 parent f2b58f3 commit 030f9bb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

compiler/rustc_middle/src/ty/trait_def.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,24 @@ impl<'tcx> TyCtxt<'tcx> {
193193
self_ty: Ty<'tcx>,
194194
) -> impl Iterator<Item = DefId> + 'tcx {
195195
let impls = self.trait_impls_of(trait_def_id);
196-
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
197-
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
196+
197+
// Non-blanket impls are grouped into two different maps:
198+
// 1) impls for references to simplifiable types
199+
if let TyKind::Ref(_, ref_ty, _) = self_ty.kind() {
200+
if let Some(simplified_ref_ty) =
201+
fast_reject::simplify_type(self, *ref_ty, TreatParams::AsCandidateKey)
202+
{
203+
if let Some(impls) = impls.impls_for_ref_x.get(&simplified_ref_ty) {
204+
return impls.iter().copied();
205+
}
206+
}
207+
}
208+
209+
// 2) the other non-blanket impls
210+
if let Some(simplified_self_ty) =
211+
fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey)
212+
{
213+
if let Some(impls) = impls.non_blanket_impls.get(&simplified_self_ty) {
198214
return impls.iter().copied();
199215
}
200216
}

0 commit comments

Comments
 (0)