Skip to content

Commit aea4220

Browse files
committed
Add test for #2989
1 parent ce4e09b commit aea4220

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/test/run-pass/issue-2989.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std;
2+
3+
trait methods {
4+
fn to_bytes() -> ~[u8];
5+
}
6+
7+
impl (): methods {
8+
fn to_bytes() -> ~[u8] {
9+
vec::from_elem(0, 0)
10+
}
11+
}
12+
13+
// the position of this function is significant! - if it comes before methods
14+
// then it works, if it comes after it then it doesnt!
15+
fn to_bools(bitv: {storage: ~[u64]}) -> ~[bool] {
16+
vec::from_fn(8, |i| {
17+
let w = i / 64;
18+
let b = i % 64;
19+
let x = 1u64 & (bitv.storage[w] >> b);
20+
x == 1u64
21+
})
22+
}
23+
24+
fn main() {
25+
let bools = ~[false, false, true, false, false, true, true, false];
26+
let bools2 = to_bools({storage: ~[0b01100100]});
27+
28+
for uint::range(0, 8) |i| {
29+
io::println(#fmt("%u => %u vs %u", i, bools[i] as uint, bools2[i] as uint));
30+
}
31+
32+
assert bools == bools2;
33+
}

0 commit comments

Comments
 (0)