Skip to content

Commit ebc079c

Browse files
committed
auto merge of #11386 : rcatolino/rust/ice-10955, r=pcwalton
So, like I mentioned in issue #10955 it doesn't seem like we need to call ```ty::subst_tps``` when the method is generic. But then I realized that this function doesn't mutate any of its input, and the return value is unused. Plus the type param substitution seems to be taken care of in ```trans_fn_ref_with_vtables```, so I thought I'd just try to remove it. As far as I can tell everything works. This closes #10955.
2 parents f6963e2 + 1812a7b commit ebc079c

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/librustc/middle/trans/meth.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,8 @@ fn emit_vtable_methods(bcx: @Block,
630630
debug!("(making impl vtable) emitting method {} at subst {}",
631631
m.repr(tcx),
632632
substs.repr(tcx));
633-
let fty = ty::subst_tps(tcx,
634-
substs,
635-
None,
636-
ty::mk_bare_fn(tcx, m.fty.clone()));
637-
if m.generics.has_type_params() || ty::type_has_self(fty) {
633+
if m.generics.has_type_params() ||
634+
ty::type_has_self(ty::mk_bare_fn(tcx, m.fty.clone())) {
638635
debug!("(making impl vtable) method has self or type params: {}",
639636
tcx.sess.str_of(ident));
640637
C_null(Type::nil().ptr_to())
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 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+
// Testing casting of a generic Struct to a Trait with a generic method.
12+
// This is test for issue 10955.
13+
#[allow(unused_variable)];
14+
15+
trait Foo {
16+
fn f<A>(a: A) -> A {
17+
a
18+
}
19+
}
20+
21+
struct Bar<T> {
22+
x: T,
23+
}
24+
25+
impl<T> Foo for Bar<T> { }
26+
27+
pub fn main() {
28+
let a = Bar { x: 1 };
29+
let b = &a as &Foo;
30+
}

0 commit comments

Comments
 (0)