-
Notifications
You must be signed in to change notification settings - Fork 4
/
0082-array_iterator.rs
56 lines (47 loc) · 1.3 KB
/
0082-array_iterator.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*!
```rudra-poc
[target]
crate = "array_iterator"
version = "1.2.0"
indexed_version = "0.2.4"
[report]
issue_url = "https://gitlab.com/kevincox/array_iterator.rs/-/issues/1"
issue_date = 2020-12-31
[[bugs]]
analyzer = "Manual"
guide = "UnsafeDataflow"
bug_class = "Other"
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
use std::mem::MaybeUninit;
use array_iterator::{Array, ArrayIterator};
struct MyArr(Vec<String>);
impl Array<String> for MyArr {
type MaybeUninit = Vec<MaybeUninit<String>>;
fn into_maybeunint(self) -> Self::MaybeUninit {
debug_assert_eq!(
std::mem::size_of::<Self::MaybeUninit>(),
std::mem::size_of::<Self>()
);
let mut partial: Self::MaybeUninit =
self.0.into_iter().map(|x| MaybeUninit::new(x)).collect();
// DANGEROUS! Appending uninitialized objects to iterator..
for _ in 0..10 {
partial.push(MaybeUninit::uninit());
}
//
partial
}
}
fn main() {
let my_arr = MyArr(vec![String::from("Hello"), String::from("World")]);
for x in ArrayIterator::new(my_arr) {
println!("{} {:?}, {}", x.len(), x.as_bytes(), x);
}
panic!(
"In DEBUG mode,\n
this panic was unreachable when tested with rustc 1.48.0 on Ubuntu 18.04"
);
}