Skip to content

Commit f8403aa

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 f092793 commit f8403aa

23 files changed

+2396
-2070
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
@@ -281,6 +281,16 @@ pub fn overlapping_impls(infcx: &InferCtxt,
281281
coherence::impl_can_satisfy(infcx, impl2_def_id, impl1_def_id)
282282
}
283283

284+
pub fn impl_obligations(tcx: &ty::ctxt,
285+
cause: ObligationCause,
286+
impl_def_id: ast::DefId,
287+
impl_substs: &subst::Substs)
288+
-> subst::VecPerParamSpace<Obligation>
289+
{
290+
let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
291+
obligations_for_generics(tcx, cause, &impl_generics, impl_substs)
292+
}
293+
284294
pub fn obligations_for_generics(tcx: &ty::ctxt,
285295
cause: ObligationCause,
286296
generics: &ty::Generics,

src/librustc/middle/traits/select.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17141714
closure_type.sig.binder_id,
17151715
&closure_type.sig,
17161716
|br| self.infcx.next_region_var(
1717-
infer::LateBoundRegion(obligation.cause.span, br)));
1717+
infer::LateBoundRegion(obligation.cause.span, br,
1718+
infer::FnCall)));
17181719

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

src/librustc/middle/ty.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -3491,43 +3491,45 @@ pub fn adjust_ty(cx: &ctxt,
34913491
}
34923492
}
34933493

3494-
match adj.autoref {
3495-
None => adjusted_ty,
3496-
Some(ref autoref) => adjust_for_autoref(cx, span, adjusted_ty, autoref)
3497-
}
3494+
adjust_ty_for_autoref(cx, span, adjusted_ty, adj.autoref.as_ref())
34983495
}
34993496
}
35003497
}
35013498
None => unadjusted_ty
35023499
};
3500+
}
35033501

3504-
fn adjust_for_autoref(cx: &ctxt,
3505-
span: Span,
3506-
ty: ty::t,
3507-
autoref: &AutoRef) -> ty::t{
3508-
match *autoref {
3509-
AutoPtr(r, m, ref a) => {
3510-
let adjusted_ty = match a {
3511-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3512-
&None => ty
3513-
};
3514-
mk_rptr(cx, r, mt {
3515-
ty: adjusted_ty,
3516-
mutbl: m
3517-
})
3518-
}
3502+
pub fn adjust_ty_for_autoref(cx: &ctxt,
3503+
span: Span,
3504+
ty: ty::t,
3505+
autoref: Option<&AutoRef>)
3506+
-> ty::t
3507+
{
3508+
match autoref {
3509+
None => ty,
35193510

3520-
AutoUnsafe(m, ref a) => {
3521-
let adjusted_ty = match a {
3522-
&Some(box ref a) => adjust_for_autoref(cx, span, ty, a),
3523-
&None => ty
3524-
};
3525-
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
3526-
}
3511+
Some(&AutoPtr(r, m, ref a)) => {
3512+
let adjusted_ty = match a {
3513+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3514+
&None => ty
3515+
};
3516+
mk_rptr(cx, r, mt {
3517+
ty: adjusted_ty,
3518+
mutbl: m
3519+
})
3520+
}
35273521

3528-
AutoUnsize(ref k) => unsize_ty(cx, ty, k, span),
3529-
AutoUnsizeUniq(ref k) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
3522+
Some(&AutoUnsafe(m, ref a)) => {
3523+
let adjusted_ty = match a {
3524+
&Some(box ref a) => adjust_ty_for_autoref(cx, span, ty, Some(a)),
3525+
&None => ty
3526+
};
3527+
mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
35303528
}
3529+
3530+
Some(&AutoUnsize(ref k)) => unsize_ty(cx, ty, k, span),
3531+
3532+
Some(&AutoUnsizeUniq(ref k)) => ty::mk_uniq(cx, unsize_ty(cx, ty, k, span)),
35313533
}
35323534
}
35333535

0 commit comments

Comments
 (0)