Apply comments from tjc
This commit is contained in:
parent
9963bd2413
commit
e8cd29ba5e
3 changed files with 23 additions and 12 deletions
|
@ -28,12 +28,12 @@ pub trait Subst {
|
||||||
// Substitution over types
|
// Substitution over types
|
||||||
//
|
//
|
||||||
// Because this is so common, we make a special optimization to avoid
|
// Because this is so common, we make a special optimization to avoid
|
||||||
// doing anything is `substs` is a no-op. I tried to generalize these
|
// doing anything if `substs` is a no-op. I tried to generalize these
|
||||||
// to all subst methods but ran into trouble due to the limitations of
|
// to all subst methods but ran into trouble due to the limitations of
|
||||||
// our current method/trait matching algorithm. - Niko
|
// our current method/trait matching algorithm. - Niko
|
||||||
|
|
||||||
trait Subst1 {
|
trait EffectfulSubst {
|
||||||
fn subst1(&self, tcx: ty::ctxt, substs: &ty::substs) -> Self;
|
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subst for ty::t {
|
impl Subst for ty::t {
|
||||||
|
@ -41,20 +41,24 @@ impl Subst for ty::t {
|
||||||
if ty::substs_is_noop(substs) {
|
if ty::substs_is_noop(substs) {
|
||||||
return *self;
|
return *self;
|
||||||
} else {
|
} else {
|
||||||
return self.subst1(tcx, substs);
|
return self.effectfulSubst(tcx, substs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Subst1 for ty::t {
|
impl EffectfulSubst for ty::t {
|
||||||
fn subst1(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
|
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
|
||||||
if !ty::type_needs_subst(*self) {
|
if !ty::type_needs_subst(*self) {
|
||||||
return *self;
|
return *self;
|
||||||
}
|
}
|
||||||
|
|
||||||
match ty::get(*self).sty {
|
match ty::get(*self).sty {
|
||||||
ty::ty_param(p) => substs.tps[p.idx],
|
ty::ty_param(p) => {
|
||||||
ty::ty_self(_) => substs.self_ty.get(),
|
substs.tps[p.idx]
|
||||||
|
}
|
||||||
|
ty::ty_self(_) => {
|
||||||
|
substs.self_ty.expect("ty_self not found in substs")
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
ty::fold_regions_and_ty(
|
ty::fold_regions_and_ty(
|
||||||
tcx, *self,
|
tcx, *self,
|
||||||
|
@ -74,8 +78,8 @@ impl Subst1 for ty::t {
|
||||||
}
|
}
|
||||||
_ => r
|
_ => r
|
||||||
},
|
},
|
||||||
|t| t.subst1(tcx, substs),
|
|t| t.effectfulSubst(tcx, substs),
|
||||||
|t| t.subst1(tcx, substs))
|
|t| t.effectfulSubst(tcx, substs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,7 +376,14 @@ pub impl<'self> LookupContext<'self> {
|
||||||
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let mut next_bound_idx = 0; // count only trait bounds
|
let mut next_bound_idx = 0; // count only trait bounds
|
||||||
let type_param_def = tcx.ty_param_defs.get(¶m_ty.def_id.node);
|
let type_param_def = match tcx.ty_param_defs.find(¶m_ty.def_id.node) {
|
||||||
|
Some(t) => t,
|
||||||
|
None => {
|
||||||
|
tcx.sess.span_bug(
|
||||||
|
self.expr.span,
|
||||||
|
fmt!("No param def for %?", param_ty));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for ty::each_bound_trait_and_supertraits(tcx, type_param_def.bounds)
|
for ty::each_bound_trait_and_supertraits(tcx, type_param_def.bounds)
|
||||||
|bound_trait_ref|
|
|bound_trait_ref|
|
||||||
|
|
|
@ -335,7 +335,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
|
||||||
ty::mk_bare_fn(tcx, copy m.fty));
|
ty::mk_bare_fn(tcx, copy m.fty));
|
||||||
|
|
||||||
// create the type parameter definitions for `foo`, applying
|
// create the type parameter definitions for `foo`, applying
|
||||||
// the substutition to any traits that appear in their bounds.
|
// the substitution to any traits that appear in their bounds.
|
||||||
|
|
||||||
// add in the type parameters from the trait
|
// add in the type parameters from the trait
|
||||||
let mut new_type_param_defs = ~[];
|
let mut new_type_param_defs = ~[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue