Skip to content

Commit 7151297

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 e4ead7b commit 7151297

23 files changed

+2396
-2066
lines changed

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This API is completely unstable and subject to change.
2929
html_root_url = "http://doc.rust-lang.org/nightly/")]
3030

3131
#![feature(default_type_params, globs, if_let, import_shadowing, macro_rules, phase, quote)]
32-
#![feature(slicing_syntax, struct_variant, unsafe_destructor)]
32+
#![feature(slicing_syntax, struct_variant, tuple_indexing, unsafe_destructor)]
3333
#![feature(rustc_diagnostic_macros)]
3434

3535
extern crate arena;

src/librustc/middle/traits/mod.rs

+10
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/traits/select.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17091709
closure_type.sig.binder_id,
17101710
&closure_type.sig,
17111711
|br| self.infcx.next_region_var(
1712-
infer::LateBoundRegion(obligation.cause.span, br)));
1712+
infer::LateBoundRegion(obligation.cause.span, br,
1713+
infer::FnCall)));
17131714

17141715
let arguments_tuple = new_signature.inputs[0];
17151716
let trait_ref = Rc::new(ty::TraitRef {

src/librustc/middle/ty.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -3470,43 +3470,45 @@ pub fn adjust_ty(cx: &ctxt,
34703470
}
34713471
}
34723472

3473-
match adj.autoref {
3474-
None => adjusted_ty,
3475-
Some(ref autoref) => adjust_for_autoref(cx, span, adjusted_ty, autoref)
3476-
}
3473+
adjust_ty_for_autoref(cx, span, adjusted_ty, adj.autoref.as_ref())
34773474
}
34783475
}
34793476
}
34803477
None => unadjusted_ty
34813478
};
3479+
}
34823480

3483-
fn adjust_for_autoref(cx: &ctxt,
3484-
span: Span,
3485-
ty: ty::t,
3486-
autoref: &AutoRef) -> ty::t{
3487-
match *autoref {
3488-
AutoPtr(r, m, ref a) => {
3489-
let adjusted_ty = match a {
3490-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3491-
&None => ty
3492-
};
3493-
mk_rptr(cx, r, mt {
3494-
ty: adjusted_ty,
3495-
mutbl: m
3496-
})
3497-
}
3481+
pub fn adjust_ty_for_autoref(cx: &ctxt,
3482+
span: Span,
3483+
ty: ty::t,
3484+
autoref: Option<&AutoRef>)
3485+
-> ty::t
3486+
{
3487+
match autoref {
3488+
None => ty,
34983489

3499-
AutoUnsafe(m, ref a) => {
3500-
let adjusted_ty = match a {
3501-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3502-
&None => ty
3503-
};
3504-
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
3505-
}
3490+
Some(&AutoPtr(r, m, ref a)) => {
3491+
let adjusted_ty = match a {
3492+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3493+
&None => ty
3494+
};
3495+
mk_rptr(cx, r, mt {
3496+
ty: adjusted_ty,
3497+
mutbl: m
3498+
})
3499+
}
35063500

3507-
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
3508-
AutoUnsizeUniq(ref k) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
3501+
Some(&AutoUnsafe(m, ref a)) => {
3502+
let adjusted_ty = match a {
3503+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3504+
&None => ty
3505+
};
3506+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
35093507
}
3508+
3509+
Some(&AutoUnsize(ref k)) => unsize_ty(cx, ty, k, span),
3510+
3511+
Some(&AutoUnsizeUniq(ref k)) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
35103512
}
35113513
}
35123514

0 commit comments

Comments
 (0)