Skip to content

Commit ad6eeb8

Browse files
committed
Don't do a bogus substitution on the transformed self ty for objects. Closes #8664.
1 parent 97d2b44 commit ad6eeb8

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -938,9 +938,18 @@ impl<'self> LookupContext<'self> {
938938

939939
// static methods should never have gotten this far:
940940
assert!(candidate.method_ty.explicit_self != sty_static);
941-
let transformed_self_ty =
942-
ty::subst(tcx, &candidate.rcvr_substs,
943-
candidate.method_ty.transformed_self_ty.unwrap());
941+
942+
let transformed_self_ty = match candidate.origin {
943+
method_object(*) => {
944+
// For annoying reasons, we've already handled the
945+
// substitution for object calls.
946+
candidate.method_ty.transformed_self_ty.unwrap()
947+
}
948+
_ => {
949+
ty::subst(tcx, &candidate.rcvr_substs,
950+
candidate.method_ty.transformed_self_ty.unwrap())
951+
}
952+
};
944953

945954
// Determine the values for the type parameters of the method.
946955
// If they were not explicitly supplied, just construct fresh

src/test/run-pass/trait-object-generics.rs

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// test for #8664
12+
13+
pub trait Trait2<A> {
14+
fn doit(&self);
15+
}
16+
17+
pub struct Impl<A1, A2, A3> {
18+
/*
19+
* With A2 we get the ICE:
20+
* 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
21+
*/
22+
t: ~Trait2<A2>
23+
}
24+
25+
impl<A1, A2, A3> Impl<A1, A2, A3> {
26+
pub fn step(&self) {
27+
self.t.doit()
28+
}
29+
}
30+
1131
// test for #8601
1232

1333
enum Type<T> { Constant }

0 commit comments

Comments
 (0)