Skip to content

Commit

Permalink
Apply comments from tjc
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Apr 9, 2013
1 parent 9963bd2 commit e8cd29b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,37 @@ pub trait Subst {
// Substitution over types
//
// 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
// our current method/trait matching algorithm. - Niko

trait Subst1 {
fn subst1(&self, tcx: ty::ctxt, substs: &ty::substs) -> Self;
trait EffectfulSubst {
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> Self;
}

impl Subst for ty::t {
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
if ty::substs_is_noop(substs) {
return *self;
} else {
return self.subst1(tcx, substs);
return self.effectfulSubst(tcx, substs);
}
}
}

impl Subst1 for ty::t {
fn subst1(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
impl EffectfulSubst for ty::t {
fn effectfulSubst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::t {
if !ty::type_needs_subst(*self) {
return *self;
}

match ty::get(*self).sty {
ty::ty_param(p) => substs.tps[p.idx],
ty::ty_self(_) => substs.self_ty.get(),
ty::ty_param(p) => {
substs.tps[p.idx]
}
ty::ty_self(_) => {
substs.self_ty.expect("ty_self not found in substs")
}
_ => {
ty::fold_regions_and_ty(
tcx, *self,
Expand All @@ -74,8 +78,8 @@ impl Subst1 for ty::t {
}
_ => r
},
|t| t.subst1(tcx, substs),
|t| t.subst1(tcx, substs))
|t| t.effectfulSubst(tcx, substs),
|t| t.effectfulSubst(tcx, substs))
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/librustc/middle/typeck/check/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,14 @@ pub impl<'self> LookupContext<'self> {

let tcx = self.tcx();
let mut next_bound_idx = 0; // count only trait bounds
let type_param_def = tcx.ty_param_defs.get(&param_ty.def_id.node);
let type_param_def = match tcx.ty_param_defs.find(&param_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)
|bound_trait_ref|
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
ty::mk_bare_fn(tcx, copy m.fty));

// 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
let mut new_type_param_defs = ~[];
Expand Down

5 comments on commit e8cd29b

@bors
Copy link
Contributor

@bors bors commented on e8cd29b Apr 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at nikomatsakis@e8cd29b

@bors
Copy link
Contributor

@bors bors commented on e8cd29b Apr 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nikomatsakis/rust/issue-4183-trait-substs = e8cd29b into auto

@bors
Copy link
Contributor

@bors bors commented on e8cd29b Apr 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nikomatsakis/rust/issue-4183-trait-substs = e8cd29b merged ok, testing candidate = 92e265c

@bors
Copy link
Contributor

@bors bors commented on e8cd29b Apr 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on e8cd29b Apr 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 92e265c

Please sign in to comment.