]> git.proxmox.com Git - rustc.git/blob - src/test/ui/run-pass/issues/issue-2989.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / issues / issue-2989.rs
1 // Copyright 2012 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 // run-pass
12 #![allow(non_camel_case_types)]
13
14 trait methods {
15 fn to_bytes(&self) -> Vec<u8> ;
16 }
17
18 impl methods for () {
19 fn to_bytes(&self) -> Vec<u8> {
20 Vec::new()
21 }
22 }
23
24 // the position of this function is significant! - if it comes before methods
25 // then it works, if it comes after it then it doesn't!
26 fn to_bools(bitv: Storage) -> Vec<bool> {
27 (0..8).map(|i| {
28 let w = i / 64;
29 let b = i % 64;
30 let x = 1 & (bitv.storage[w] >> b);
31 x == 1
32 }).collect()
33 }
34
35 struct Storage { storage: Vec<u64> }
36
37 pub fn main() {
38 let bools = vec![false, false, true, false, false, true, true, false];
39 let bools2 = to_bools(Storage{storage: vec![0b01100100]});
40
41 for i in 0..8 {
42 println!("{} => {} vs {}", i, bools[i], bools2[i]);
43 }
44
45 assert_eq!(bools, bools2);
46 }