]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-2989.rs
Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis
[rust.git] / src / test / ui / issues / issue-2989.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3
4 trait methods {
5     fn to_bytes(&self) -> Vec<u8> ;
6 }
7
8 impl methods for () {
9     fn to_bytes(&self) -> Vec<u8> {
10         Vec::new()
11     }
12 }
13
14 // the position of this function is significant! - if it comes before methods
15 // then it works, if it comes after it then it doesn't!
16 fn to_bools(bitv: Storage) -> Vec<bool> {
17     (0..8).map(|i| {
18         let w = i / 64;
19         let b = i % 64;
20         let x = 1 & (bitv.storage[w] >> b);
21         x == 1
22     }).collect()
23 }
24
25 struct Storage { storage: Vec<u64> }
26
27 pub fn main() {
28     let bools = vec![false, false, true, false, false, true, true, false];
29     let bools2 = to_bools(Storage{storage: vec![0b01100100]});
30
31     for i in 0..8 {
32         println!("{} => {} vs {}", i, bools[i], bools2[i]);
33     }
34
35     assert_eq!(bools, bools2);
36 }