Skip to content

Commit 6047dd3

Browse files
committed
Fix vtable calculations when translating static methods. Closes #4165
1 parent 0494b07 commit 6047dd3

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/librustc/middle/trans/meth.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,7 @@ fn combine_impl_and_methods_origins(bcx: block,
515515
let m_boundss = vec::view(*r_m_bounds, n_r_m_tps - n_m_tps, n_r_m_tps);
516516
517517
// Flatten out to find the number of vtables the method expects.
518-
let m_vtables = m_boundss.foldl(0, |sum, m_bounds| {
519-
m_bounds.foldl(*sum, |sum, m_bound| {
520-
(*sum) + match (*m_bound) {
521-
ty::bound_copy | ty::bound_owned |
522-
ty::bound_send | ty::bound_const => 0,
523-
ty::bound_trait(_) => 1
524-
}
525-
})
526-
});
518+
let m_vtables = ty::count_traits_and_supertraits(tcx, m_boundss);
527519
528520
// Find the vtables we computed at type check time and monomorphize them
529521
let r_m_origins = match node_vtables(bcx, callee_id) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub trait Number: NumConv {
2+
static pure fn from<T:Number>(n: T) -> self;
3+
}
4+
5+
pub impl float: Number {
6+
static pure fn from<T:Number>(n: T) -> float { n.to_float() }
7+
}
8+
9+
pub trait NumConv {
10+
pure fn to_float(&self) -> float;
11+
}
12+
13+
pub impl float: NumConv {
14+
pure fn to_float(&self) -> float { *self }
15+
}
16+
17+
fn main() {
18+
let _: float = Number::from(0.0f);
19+
}

0 commit comments

Comments
 (0)