Skip to content

Commit 97d2b44

Browse files
committed
Substitute into the impl method rather than the trait method when emitting vtables. Closes #8601.
1 parent 8a9cdda commit 97d2b44

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/librustc/middle/trans/meth.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,20 +577,23 @@ fn emit_vtable_methods(bcx: @mut Block,
577577

578578
let trait_method_def_ids = ty::trait_method_def_ids(tcx, trt_id);
579579
do trait_method_def_ids.map |method_def_id| {
580-
let im = ty::method(tcx, *method_def_id);
580+
let ident = ty::method(tcx, *method_def_id).ident;
581+
// The substitutions we have are on the impl, so we grab
582+
// the method type from the impl to substitute into.
583+
let m_id = method_with_name(ccx, impl_id, ident);
584+
let m = ty::method(tcx, m_id);
585+
debug!("(making impl vtable) emitting method %s at subst %s",
586+
m.repr(tcx),
587+
substs.repr(tcx));
581588
let fty = ty::subst_tps(tcx,
582589
substs,
583590
None,
584-
ty::mk_bare_fn(tcx, im.fty.clone()));
585-
if im.generics.has_type_params() || ty::type_has_self(fty) {
591+
ty::mk_bare_fn(tcx, m.fty.clone()));
592+
if m.generics.has_type_params() || ty::type_has_self(fty) {
586593
debug!("(making impl vtable) method has self or type params: %s",
587-
tcx.sess.str_of(im.ident));
594+
tcx.sess.str_of(ident));
588595
C_null(Type::nil().ptr_to())
589596
} else {
590-
debug!("(making impl vtable) adding method to vtable: %s",
591-
tcx.sess.str_of(im.ident));
592-
let m_id = method_with_name(ccx, impl_id, im.ident);
593-
594597
trans_fn_ref_with_vtables(bcx, m_id, 0,
595598
substs, Some(vtables)).llfn
596599
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// test for #8601
12+
13+
enum Type<T> { Constant }
14+
15+
trait Trait<K,V> {
16+
fn method(&self,Type<(K,V)>) -> int;
17+
}
18+
19+
impl<V> Trait<u8,V> for () {
20+
fn method(&self, _x: Type<(u8,V)>) -> int { 0 }
21+
}
22+
23+
fn main () {
24+
let a = @() as @Trait<u8, u8>;
25+
assert_eq!(a.method(Constant), 0);
26+
}

0 commit comments

Comments
 (0)