Skip to content

Commit 09033dc

Browse files
committed
Test generic methods
1 parent b47d969 commit 09033dc

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn trans_constval<'blk, 'tcx>(bcx: common::Block<'blk, 'tcx>,
131131
}
132132
},
133133
ConstVal::Array(id, _) | ConstVal::Repeat(id, _) => {
134-
let expr = ccx.tcx().map.expect_expr(id);
134+
let expr = bcx.tcx().map.expect_expr(id);
135135
expr::trans(bcx, expr).datum.val
136136
},
137137
ConstVal::Function(_) => {

src/test/run-pass/mir_refs_correct.rs

+56
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ trait X {
2525
fn hoy2() -> u8 { 45 }
2626
}
2727

28+
trait F<U> {
29+
fn f(self, other: U) -> u64;
30+
}
31+
32+
impl F<u32> for u32 {
33+
fn f(self, other: u32) -> u64 { self as u64 + other as u64 }
34+
}
35+
36+
impl F<u64> for u32 {
37+
fn f(self, other: u64) -> u64 { self as u64 - other }
38+
}
39+
40+
impl F<u64> for u64 {
41+
fn f(self, other: u64) -> u64 { self * other }
42+
}
43+
44+
impl F<u32> for u64 {
45+
fn f(self, other: u32) -> u64 { self ^ other as u64 }
46+
}
47+
48+
trait T<I, O> {
49+
fn staticmeth(i: I, o: O) -> (I, O) { (i, o) }
50+
}
51+
52+
impl<I, O> T<I, O> for O {}
53+
2854
impl X for S {}
2955

3056
enum E {
@@ -118,6 +144,31 @@ fn t15() -> fn(&S)-> u8 {
118144
S::hey2
119145
}
120146

147+
#[rustc_mir]
148+
fn t16() -> fn(u32, u32)->u64 {
149+
F::f
150+
}
151+
152+
#[rustc_mir]
153+
fn t17() -> fn(u32, u64)->u64 {
154+
F::f
155+
}
156+
157+
#[rustc_mir]
158+
fn t18() -> fn(u64, u64)->u64 {
159+
F::f
160+
}
161+
162+
#[rustc_mir]
163+
fn t19() -> fn(u64, u32)->u64 {
164+
F::f
165+
}
166+
167+
#[rustc_mir]
168+
fn t20() -> fn(u64, u32)->(u64, u32) {
169+
<u32 as T<_, _>>::staticmeth
170+
}
171+
121172
fn main(){
122173
unsafe {
123174
assert_eq!(t1()(), regular());
@@ -151,5 +202,10 @@ fn main(){
151202

152203
assert_eq!(t14()(), <S as X>::hoy2());
153204
assert_eq!(t15()(&s), S::hey2(&s));
205+
assert_eq!(t16()(10u32, 20u32), F::f(10u32, 20u32));
206+
assert_eq!(t17()(30u32, 10u64), F::f(30u32, 10u64));
207+
assert_eq!(t18()(50u64, 5u64), F::f(50u64, 5u64));
208+
assert_eq!(t19()(322u64, 2u32), F::f(322u64, 2u32));
209+
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
154210
}
155211
}

0 commit comments

Comments
 (0)