Skip to content

Commit

Permalink
Don't do a bogus substitution on the transformed self ty for objects. C…
Browse files Browse the repository at this point in the history
…loses #8664.
  • Loading branch information
msullivan committed Aug 22, 2013
1 parent 97d2b44 commit ad6eeb8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/librustc/middle/typeck/check/method.rs
Expand Up @@ -938,9 +938,18 @@ impl<'self> LookupContext<'self> {

// static methods should never have gotten this far:
assert!(candidate.method_ty.explicit_self != sty_static);
let transformed_self_ty =
ty::subst(tcx, &candidate.rcvr_substs,
candidate.method_ty.transformed_self_ty.unwrap());

let transformed_self_ty = match candidate.origin {
method_object(*) => {
// For annoying reasons, we've already handled the
// substitution for object calls.
candidate.method_ty.transformed_self_ty.unwrap()
}
_ => {
ty::subst(tcx, &candidate.rcvr_substs,
candidate.method_ty.transformed_self_ty.unwrap())
}
};

// Determine the values for the type parameters of the method.
// If they were not explicitly supplied, just construct fresh
Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/trait-object-generics.rs
Expand Up @@ -8,6 +8,26 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// test for #8664

pub trait Trait2<A> {
fn doit(&self);
}

pub struct Impl<A1, A2, A3> {
/*
* With A2 we get the ICE:
* task <unnamed> failed at 'index out of bounds: the len is 1 but the index is 1', /home/tortue/rust_compiler_newest/src/librustc/middle/subst.rs:58
*/
t: ~Trait2<A2>
}

impl<A1, A2, A3> Impl<A1, A2, A3> {
pub fn step(&self) {
self.t.doit()
}
}

// test for #8601

enum Type<T> { Constant }
Expand Down

4 comments on commit ad6eeb8

@bors
Copy link
Contributor

@bors bors commented on ad6eeb8 Aug 22, 2013

Choose a reason for hiding this comment

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

saw approval from graydon
at msullivan@ad6eeb8

@bors
Copy link
Contributor

@bors bors commented on ad6eeb8 Aug 22, 2013

Choose a reason for hiding this comment

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

merging msullivan/rust/default-methods = ad6eeb8 into auto

@bors
Copy link
Contributor

@bors bors commented on ad6eeb8 Aug 22, 2013

Choose a reason for hiding this comment

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

msullivan/rust/default-methods = ad6eeb8 merged ok, testing candidate = 1b11cd9a

@bors
Copy link
Contributor

@bors bors commented on ad6eeb8 Aug 22, 2013

Please sign in to comment.