Skip to content

Commit 2927f33

Browse files
committed
---
yaml --- r: 155130 b: refs/heads/try2 c: 688ddf7 h: refs/heads/master v: v3
1 parent ee1f163 commit 2927f33

File tree

12 files changed

+1272
-1801
lines changed

12 files changed

+1272
-1801
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 088c94ae96aa139db6b6f0c5640c720ff107ee0f
8+
refs/heads/try2: 688ddf79156aa01a2507412c9b766f48ef208b04
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/kind.rs

Lines changed: 46 additions & 437 deletions
Large diffs are not rendered by default.

branches/try2/src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5423,7 +5423,7 @@ impl BorrowKind {
54235423
* Returns a mutability `m` such that an `&m T` pointer could
54245424
* be used to obtain this borrow kind. Because borrow kinds
54255425
* are richer than mutabilities, we sometimes have to pick a
5426-
* mutability that is stornger than necessary so that it at
5426+
* mutability that is stronger than necessary so that it at
54275427
* least *would permit* the borrow in question.
54285428
*/
54295429

branches/try2/src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,9 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
555555
None);
556556
match tcx.def_map.borrow().find(&pat.id) {
557557
Some(def) => {
558-
let item_type = ty::lookup_item_type(tcx, def.def_id());
559-
let substitutions = fcx.infcx().fresh_substs_for_type(
560-
pat.span, &item_type.generics);
558+
let struct_ty = fcx.instantiate_item_type(pat.span, def.def_id());
561559
check_struct_pat(pcx, pat.span, fields.as_slice(),
562-
etc, def.def_id(), &substitutions);
560+
etc, def.def_id(), &struct_ty.substs);
563561
}
564562
None => {
565563
tcx.sess.span_bug(pat.span,

branches/try2/src/librustc/middle/typeck/check/method.rs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ obtained the type `Foo`, we would never match this method.
8282

8383
use middle::subst;
8484
use middle::subst::Subst;
85+
use middle::traits;
8586
use middle::ty::*;
8687
use middle::ty;
8788
use middle::typeck::astconv::AstConv;
@@ -91,7 +92,6 @@ use middle::typeck::infer;
9192
use middle::typeck::MethodCallee;
9293
use middle::typeck::{MethodOrigin, MethodParam};
9394
use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure, MethodObject};
94-
use middle::typeck::{param_index};
9595
use middle::typeck::check::regionmanip::replace_late_bound_regions_in_fn_sig;
9696
use middle::typeck::TypeAndSubsts;
9797
use util::common::indenter;
@@ -538,14 +538,12 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
538538
return
539539
}
540540

541-
let vcx = self.fcx.vtable_context();
542-
543541
// Get the tupled type of the arguments.
544542
let arguments_type = *closure_function_type.sig.inputs.get(0);
545543
let return_type = closure_function_type.sig.output;
546544

547545
let closure_region =
548-
vcx.infcx.next_region_var(infer::MiscVariable(self.span));
546+
self.fcx.infcx().next_region_var(infer::MiscVariable(self.span));
549547
let unboxed_closure_type = ty::mk_unboxed_closure(self.tcx(),
550548
closure_did,
551549
closure_region);
@@ -555,7 +553,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
555553
rcvr_substs: subst::Substs::new_trait(
556554
vec![arguments_type, return_type],
557555
vec![],
558-
*vcx.infcx.next_ty_vars(1).get(0)),
556+
*self.fcx.infcx().next_ty_vars(1).get(0)),
559557
method_ty: method,
560558
origin: MethodStaticUnboxedClosure(closure_did),
561559
});
@@ -618,7 +616,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
618616

619617
self.push_inherent_candidates_from_bounds_inner(
620618
&[trait_ref.clone()],
621-
|_this, new_trait_ref, m, method_num, _bound_num| {
619+
|_this, new_trait_ref, m, method_num| {
622620
let vtable_index =
623621
get_method_index(tcx, &*new_trait_ref,
624622
trait_ref.clone(), method_num);
@@ -633,7 +631,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
633631
rcvr_substs: new_trait_ref.substs.clone(),
634632
method_ty: Rc::new(m),
635633
origin: MethodObject(MethodObject {
636-
trait_id: new_trait_ref.def_id,
634+
trait_ref: new_trait_ref,
637635
object_trait_id: did,
638636
method_num: method_num,
639637
real_index: vtable_index
@@ -652,22 +650,20 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
652650
rcvr_ty,
653651
param_ty.space,
654652
param_ty.idx,
655-
restrict_to,
656-
param_index { space: param_ty.space, index: param_ty.idx });
653+
restrict_to);
657654
}
658655

659656

660657
fn push_inherent_candidates_from_bounds(&mut self,
661658
self_ty: ty::t,
662659
space: subst::ParamSpace,
663660
index: uint,
664-
restrict_to: Option<DefId>,
665-
param: param_index) {
661+
restrict_to: Option<DefId>) {
666662
let bounds =
667663
self.fcx.inh.param_env.bounds.get(space, index).trait_bounds
668664
.as_slice();
669665
self.push_inherent_candidates_from_bounds_inner(bounds,
670-
|this, trait_ref, m, method_num, bound_num| {
666+
|this, trait_ref, m, method_num| {
671667
match restrict_to {
672668
Some(trait_did) => {
673669
if trait_did != trait_ref.def_id {
@@ -701,10 +697,8 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
701697
rcvr_substs: trait_ref.substs.clone(),
702698
method_ty: m,
703699
origin: MethodParam(MethodParam {
704-
trait_id: trait_ref.def_id,
700+
trait_ref: trait_ref,
705701
method_num: method_num,
706-
param_num: param,
707-
bound_num: bound_num,
708702
})
709703
})
710704
})
@@ -718,15 +712,16 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
718712
mk_cand: |this: &mut LookupContext,
719713
tr: Rc<TraitRef>,
720714
m: Rc<ty::Method>,
721-
method_num: uint,
722-
bound_num: uint|
723-
-> Option<Candidate>) {
715+
method_num: uint|
716+
-> Option<Candidate>)
717+
{
724718
let tcx = self.tcx();
725-
let mut next_bound_idx = 0; // count only trait bounds
726-
727-
ty::each_bound_trait_and_supertraits(tcx, bounds, |bound_trait_ref| {
728-
let this_bound_idx = next_bound_idx;
729-
next_bound_idx += 1;
719+
let mut cache = HashSet::new();
720+
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
721+
// Already visited this trait, skip it.
722+
if !cache.insert(bound_trait_ref.def_id) {
723+
continue;
724+
}
730725

731726
let trait_items = ty::trait_items(tcx, bound_trait_ref.def_id);
732727
match trait_items.iter().position(|ti| {
@@ -745,8 +740,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
745740
match mk_cand(self,
746741
bound_trait_ref,
747742
method,
748-
pos,
749-
this_bound_idx) {
743+
pos) {
750744
Some(cand) => {
751745
debug!("pushing inherent candidate for param: {}",
752746
cand.repr(self.tcx()));
@@ -761,8 +755,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
761755
// check next trait or bound
762756
}
763757
}
764-
true
765-
});
758+
}
766759
}
767760

768761

@@ -773,7 +766,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
773766

774767
let impl_items = self.tcx().impl_items.borrow();
775768
for impl_infos in self.tcx().inherent_impls.borrow().find(&did).iter() {
776-
for impl_did in impl_infos.borrow().iter() {
769+
for impl_did in impl_infos.iter() {
777770
let items = impl_items.get(impl_did);
778771
self.push_candidates_from_impl(*impl_did,
779772
items.as_slice(),
@@ -825,11 +818,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
825818
// determine the `self` of the impl with fresh
826819
// variables for each parameter:
827820
let span = self.self_expr.map_or(self.span, |e| e.span);
828-
let vcx = self.fcx.vtable_context();
829821
let TypeAndSubsts {
830822
substs: impl_substs,
831823
ty: impl_ty
832-
} = impl_self_ty(&vcx, span, impl_did);
824+
} = impl_self_ty(self.fcx, span, impl_did);
833825

834826
let condition = match method.explicit_self {
835827
ByReferenceExplicitSelfCategory(_, mt) if mt == MutMutable =>
@@ -877,7 +869,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
877869
adjustment {:?} for {}", adjustment, self.ty_to_string(self_ty));
878870
match adjustment {
879871
Some((self_expr_id, adj)) => {
880-
self.fcx.write_adjustment(self_expr_id, adj);
872+
self.fcx.write_adjustment(self_expr_id, self.span, adj);
881873
}
882874
None => {}
883875
}
@@ -1109,7 +1101,9 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
11091101

11101102
ty_err => None,
11111103

1112-
ty_infer(TyVar(_)) => {
1104+
ty_infer(TyVar(_)) |
1105+
ty_infer(SkolemizedTy(_)) |
1106+
ty_infer(SkolemizedIntTy(_)) => {
11131107
self.bug(format!("unexpected type: {}",
11141108
self.ty_to_string(self_ty)).as_slice());
11151109
}
@@ -1150,6 +1144,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
11501144
Some(self_expr_id) => {
11511145
self.fcx.write_adjustment(
11521146
self_expr_id,
1147+
self.span,
11531148
ty::AutoDerefRef(ty::AutoDerefRef {
11541149
autoderefs: autoderefs,
11551150
autoref: Some(kind(region, *mutbl))
@@ -1209,7 +1204,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
12091204

12101205
// return something so we don't get errors for every mutability
12111206
return Some(MethodCallee {
1212-
origin: relevant_candidates.get(0).origin,
1207+
origin: relevant_candidates.get(0).origin.clone(),
12131208
ty: ty::mk_err(),
12141209
substs: subst::Substs::empty()
12151210
});
@@ -1237,12 +1232,14 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
12371232
candidate_b.repr(self.tcx()));
12381233
match (&candidate_a.origin, &candidate_b.origin) {
12391234
(&MethodParam(ref p1), &MethodParam(ref p2)) => {
1240-
let same_trait = p1.trait_id == p2.trait_id;
1241-
let same_method = p1.method_num == p2.method_num;
1242-
let same_param = p1.param_num == p2.param_num;
1243-
// The bound number may be different because
1244-
// multiple bounds may lead to the same trait
1245-
// impl
1235+
let same_trait =
1236+
p1.trait_ref.def_id == p2.trait_ref.def_id;
1237+
let same_method =
1238+
p1.method_num == p2.method_num;
1239+
// it's ok to compare self-ty with `==` here because
1240+
// they are always a TyParam
1241+
let same_param =
1242+
p1.trait_ref.self_ty() == p2.trait_ref.self_ty();
12461243
same_trait && same_method && same_param
12471244
}
12481245
_ => false
@@ -1369,13 +1366,13 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
13691366
}
13701367
}
13711368

1372-
self.fcx.add_region_obligations_for_parameters(
1373-
self.span,
1369+
self.fcx.add_obligations_for_parameters(
1370+
traits::ObligationCause::misc(self.span),
13741371
&all_substs,
13751372
&candidate.method_ty.generics);
13761373

13771374
MethodCallee {
1378-
origin: candidate.origin,
1375+
origin: candidate.origin.clone(),
13791376
ty: fty,
13801377
substs: all_substs
13811378
}
@@ -1452,10 +1449,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
14521449
MethodStaticUnboxedClosure(_) => bad = false,
14531450
// FIXME: does this properly enforce this on everything now
14541451
// that self has been merged in? -sully
1455-
MethodParam(MethodParam { trait_id: trait_id, .. }) |
1456-
MethodObject(MethodObject { trait_id: trait_id, .. }) => {
1452+
MethodParam(MethodParam { trait_ref: ref trait_ref, .. }) |
1453+
MethodObject(MethodObject { trait_ref: ref trait_ref, .. }) => {
14571454
bad = self.tcx().destructor_for_type.borrow()
1458-
.contains_key(&trait_id);
1455+
.contains_key(&trait_ref.def_id);
14591456
}
14601457
}
14611458

@@ -1602,10 +1599,10 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
16021599
self.report_static_candidate(idx, did)
16031600
}
16041601
MethodParam(ref mp) => {
1605-
self.report_param_candidate(idx, (*mp).trait_id)
1602+
self.report_param_candidate(idx, mp.trait_ref.def_id)
16061603
}
16071604
MethodObject(ref mo) => {
1608-
self.report_trait_candidate(idx, mo.trait_id)
1605+
self.report_trait_candidate(idx, mo.trait_ref.def_id)
16091606
}
16101607
}
16111608
}

0 commit comments

Comments
 (0)