Skip to content

Commit 7dd9579

Browse files
committed
Test generic methods
1 parent b3720ea commit 7dd9579

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-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

+63
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 {
@@ -33,6 +59,7 @@ enum E {
3359

3460
const C: u8 = 84;
3561
const C2: [u8; 5] = [42; 5];
62+
const C3: [u8; 3] = [42, 41, 40];
3663

3764
fn regular() -> u8 {
3865
21
@@ -108,6 +135,11 @@ fn t13() -> [u8; 5] {
108135
C2
109136
}
110137

138+
#[rustc_mir]
139+
fn t13_2() -> [u8; 3] {
140+
C3
141+
}
142+
111143
#[rustc_mir]
112144
fn t14() -> fn()-> u8 {
113145
<S as X>::hoy2
@@ -118,6 +150,31 @@ fn t15() -> fn(&S)-> u8 {
118150
S::hey2
119151
}
120152

153+
#[rustc_mir]
154+
fn t16() -> fn(u32, u32)->u64 {
155+
F::f
156+
}
157+
158+
#[rustc_mir]
159+
fn t17() -> fn(u32, u64)->u64 {
160+
F::f
161+
}
162+
163+
#[rustc_mir]
164+
fn t18() -> fn(u64, u64)->u64 {
165+
F::f
166+
}
167+
168+
#[rustc_mir]
169+
fn t19() -> fn(u64, u32)->u64 {
170+
F::f
171+
}
172+
173+
#[rustc_mir]
174+
fn t20() -> fn(u64, u32)->(u64, u32) {
175+
<u32 as T<_, _>>::staticmeth
176+
}
177+
121178
fn main(){
122179
unsafe {
123180
assert_eq!(t1()(), regular());
@@ -148,8 +205,14 @@ fn main(){
148205

149206
assert_eq!(t12(), C);
150207
assert_eq!(t13(), C2);
208+
assert_eq!(t13_2(), C3);
151209

152210
assert_eq!(t14()(), <S as X>::hoy2());
153211
assert_eq!(t15()(&s), S::hey2(&s));
212+
assert_eq!(t16()(10u32, 20u32), F::f(10u32, 20u32));
213+
assert_eq!(t17()(30u32, 10u64), F::f(30u32, 10u64));
214+
assert_eq!(t18()(50u64, 5u64), F::f(50u64, 5u64));
215+
assert_eq!(t19()(322u64, 2u32), F::f(322u64, 2u32));
216+
assert_eq!(t20()(123u64, 38u32), <u32 as T<_, _>>::staticmeth(123, 38));
154217
}
155218
}

0 commit comments

Comments
 (0)