Skip to content

Commit 0b44470

Browse files
committed
Rewrite method resolution to be cleaner, more correct, and to lay
groundwork for better performance. Key points: - Separate out determining which method to use from actually selecting a method (this should enable caching, as well as the pcwalton fast-reject strategy). - Merge the impl selection back into method resolution and don't rely on trait matching (this should perform better but also is needed to resolve some kind of conflicts, see e.g. `method-two-traits-distinguished-via-where-clause.rs`) - Purge a lot of out-of-date junk and coercions from method lookups.
1 parent e84e7a0 commit 0b44470

File tree

17 files changed

+2318
-2004
lines changed

17 files changed

+2318
-2004
lines changed

src/librustc/middle/traits/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ pub fn overlapping_impls(infcx: &InferCtxt,
276276
coherence::impl_can_satisfy(infcx, impl2_def_id, impl1_def_id)
277277
}
278278

279+
pub fn impl_obligations(tcx: &ty::ctxt,
280+
cause: ObligationCause,
281+
impl_def_id: ast::DefId,
282+
impl_substs: &subst::Substs)
283+
-> subst::VecPerParamSpace<Obligation>
284+
{
285+
let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
286+
obligations_for_generics(tcx, cause, &impl_generics, impl_substs)
287+
}
288+
279289
pub fn obligations_for_generics(tcx: &ty::ctxt,
280290
cause: ObligationCause,
281291
generics: &ty::Generics,

src/librustc/middle/ty.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,43 +3477,45 @@ pub fn adjust_ty(cx: &ctxt,
34773477
}
34783478
}
34793479

3480-
match adj.autoref {
3481-
None => adjusted_ty,
3482-
Some(ref autoref) => adjust_for_autoref(cx, span, adjusted_ty, autoref)
3483-
}
3480+
adjust_ty_for_autoref(cx, span, adjusted_ty, adj.autoref.as_ref())
34843481
}
34853482
}
34863483
}
34873484
None => unadjusted_ty
34883485
};
3486+
}
34893487

3490-
fn adjust_for_autoref(cx: &ctxt,
3491-
span: Span,
3492-
ty: ty::t,
3493-
autoref: &AutoRef) -> ty::t{
3494-
match *autoref {
3495-
AutoPtr(r, m, ref a) => {
3496-
let adjusted_ty = match a {
3497-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3498-
&None => ty
3499-
};
3500-
mk_rptr(cx, r, mt {
3501-
ty: adjusted_ty,
3502-
mutbl: m
3503-
})
3504-
}
3488+
pub fn adjust_ty_for_autoref(cx: &ctxt,
3489+
span: Span,
3490+
ty: ty::t,
3491+
autoref: Option<&AutoRef>)
3492+
-> ty::t
3493+
{
3494+
match autoref {
3495+
None => ty,
35053496

3506-
AutoUnsafe(m, ref a) => {
3507-
let adjusted_ty = match a {
3508-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3509-
&None => ty
3510-
};
3511-
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
3512-
}
3497+
Some(&AutoPtr(r, m, ref a)) => {
3498+
let adjusted_ty = match a {
3499+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3500+
&None => ty
3501+
};
3502+
mk_rptr(cx, r, mt {
3503+
ty: adjusted_ty,
3504+
mutbl: m
3505+
})
3506+
}
35133507

3514-
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
3515-
AutoUnsizeUniq(ref k) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
3508+
Some(&AutoUnsafe(m, ref a)) => {
3509+
let adjusted_ty = match a {
3510+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3511+
&None => ty
3512+
};
3513+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
35163514
}
3515+
3516+
Some(&AutoUnsize(ref k)) => unsize_ty(cx, ty, k, span),
3517+
3518+
Some(&AutoUnsizeUniq(ref k)) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
35173519
}
35183520
}
35193521

0 commit comments

Comments
 (0)