Skip to content

Commit 3589094

Browse files
committed
---
yaml --- r: 95963 b: refs/heads/dist-snap c: 85c51d3 h: refs/heads/master i: 95961: 1b9ae37 95959: be85e12 v: v3
1 parent 5261e24 commit 3589094

File tree

4 files changed

+412
-335
lines changed

4 files changed

+412
-335
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 8e1de17757a204948b8d0ead4990b2602bc81298
9+
refs/heads/dist-snap: 85c51d3b02e421e2ab99c330e0d8212293f64f04
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/subst.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
// Type substitutions.
1212

13-
1413
use middle::ty;
14+
use middle::ty_fold;
15+
use middle::ty_fold::TypeFolder;
1516
use syntax::opt_vec::OptVec;
16-
use util::ppaux::Repr;
17+
use std::at_vec;
1718

1819
///////////////////////////////////////////////////////////////////////////
1920
// Public trait `Subst`
@@ -33,39 +34,43 @@ pub trait Subst {
3334
// to all subst methods but ran into trouble due to the limitations of
3435
// our current method/trait matching algorithm. - Niko
3536

36-
trait EffectfulSubst {
37-
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> Self;
38-
}
39-
4037
impl Subst for ty::t {
4138
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
4239
if ty::substs_is_noop(substs) {
43-
return *self;
40+
*self
4441
} else {
45-
return self.effectfulSubst(tcx, substs);
42+
let mut folder = SubstFolder {tcx: tcx, substs: substs};
43+
folder.fold_ty(*self)
4644
}
4745
}
4846
}
4947

50-
impl EffectfulSubst for ty::t {
51-
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
52-
if !ty::type_needs_subst(*self) {
53-
return *self;
48+
struct SubstFolder<'self> {
49+
tcx: ty::ctxt,
50+
substs: &'self ty::substs
51+
}
52+
53+
impl<'self> TypeFolder for SubstFolder<'self> {
54+
fn tcx(&self) -> ty::ctxt { self.tcx }
55+
56+
fn fold_region(&mut self, r: ty::Region) -> ty::Region {
57+
r.subst(self.tcx, self.substs)
58+
}
59+
60+
fn fold_ty(&mut self, t: ty::t) -> ty::t {
61+
if !ty::type_needs_subst(t) {
62+
return t;
5463
}
5564

56-
match ty::get(*self).sty {
65+
match ty::get(t).sty {
5766
ty::ty_param(p) => {
58-
substs.tps[p.idx]
67+
self.substs.tps[p.idx]
5968
}
6069
ty::ty_self(_) => {
61-
substs.self_ty.expect("ty_self not found in substs")
70+
self.substs.self_ty.expect("ty_self not found in substs")
6271
}
6372
_ => {
64-
ty::fold_regions_and_ty(
65-
tcx, *self,
66-
|r| r.subst(tcx, substs),
67-
|t| t.effectfulSubst(tcx, substs),
68-
|t| t.effectfulSubst(tcx, substs))
73+
ty_fold::super_fold_ty(self, t)
6974
}
7075
}
7176
}
@@ -80,6 +85,12 @@ impl<T:Subst> Subst for ~[T] {
8085
}
8186
}
8287

88+
impl<T:Subst> Subst for @[T] {
89+
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> @[T] {
90+
at_vec::map(*self, |t| t.subst(tcx, substs))
91+
}
92+
}
93+
8394
impl<T:Subst> Subst for OptVec<T> {
8495
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> OptVec<T> {
8596
self.map(|t| t.subst(tcx, substs))
@@ -134,7 +145,8 @@ impl Subst for ty::RegionSubsts {
134145

135146
impl Subst for ty::BareFnTy {
136147
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::BareFnTy {
137-
ty::fold_bare_fn_ty(self, |t| t.subst(tcx, substs))
148+
let mut folder = SubstFolder {tcx: tcx, substs: substs};
149+
folder.fold_bare_fn_ty(self)
138150
}
139151
}
140152

0 commit comments

Comments
 (0)