Skip to content

Commit 294b7a5

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 0b48001 commit 294b7a5

File tree

17 files changed

+2323
-2009
lines changed

17 files changed

+2323
-2009
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
@@ -3485,43 +3485,45 @@ pub fn adjust_ty(cx: &ctxt,
34853485
}
34863486
}
34873487

3488-
match adj.autoref {
3489-
None => adjusted_ty,
3490-
Some(ref autoref) => adjust_for_autoref(cx, span, adjusted_ty, autoref)
3491-
}
3488+
adjust_ty_for_autoref(cx, span, adjusted_ty, adj.autoref.as_ref())
34923489
}
34933490
}
34943491
}
34953492
None => unadjusted_ty
34963493
};
3494+
}
34973495

3498-
fn adjust_for_autoref(cx: &ctxt,
3499-
span: Span,
3500-
ty: ty::t,
3501-
autoref: &AutoRef) -> ty::t{
3502-
match *autoref {
3503-
AutoPtr(r, m, ref a) => {
3504-
let adjusted_ty = match a {
3505-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3506-
&None => ty
3507-
};
3508-
mk_rptr(cx, r, mt {
3509-
ty: adjusted_ty,
3510-
mutbl: m
3511-
})
3512-
}
3496+
pub fn adjust_ty_for_autoref(cx: &ctxt,
3497+
span: Span,
3498+
ty: ty::t,
3499+
autoref: Option<&AutoRef>)
3500+
-> ty::t
3501+
{
3502+
match autoref {
3503+
None => ty,
35133504

3514-
AutoUnsafe(m, ref a) => {
3515-
let adjusted_ty = match a {
3516-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3517-
&None => ty
3518-
};
3519-
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
3520-
}
3505+
Some(&AutoPtr(r, m, ref a)) => {
3506+
let adjusted_ty = match a {
3507+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3508+
&None => ty
3509+
};
3510+
mk_rptr(cx, r, mt {
3511+
ty: adjusted_ty,
3512+
mutbl: m
3513+
})
3514+
}
35213515

3522-
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
3523-
AutoUnsizeUniq(ref k) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
3516+
Some(&AutoUnsafe(m, ref a)) => {
3517+
let adjusted_ty = match a {
3518+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3519+
&None => ty
3520+
};
3521+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
35243522
}
3523+
3524+
Some(&AutoUnsize(ref k)) => unsize_ty(cx, ty, k, span),
3525+
3526+
Some(&AutoUnsizeUniq(ref k)) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
35253527
}
35263528
}
35273529

0 commit comments

Comments
 (0)