From ad6eeb843b3f21bd51bc6d89d58a75367b7439df Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 21 Aug 2013 19:58:27 -0700 Subject: [PATCH] Don't do a bogus substitution on the transformed self ty for objects. Closes #8664. --- src/librustc/middle/typeck/check/method.rs | 15 ++++++++++++--- src/test/run-pass/trait-object-generics.rs | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index c8d3bdaab2892..c15f6a254457e 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -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 diff --git a/src/test/run-pass/trait-object-generics.rs b/src/test/run-pass/trait-object-generics.rs index 7bee660410dfc..12b6af295202d 100644 --- a/src/test/run-pass/trait-object-generics.rs +++ b/src/test/run-pass/trait-object-generics.rs @@ -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 { + fn doit(&self); +} + +pub struct Impl { + /* + * With A2 we get the ICE: + * task 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 +} + +impl Impl { + pub fn step(&self) { + self.t.doit() + } +} + // test for #8601 enum Type { Constant }