]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/fat_ptr.rs
Auto merge of #99609 - workingjubilee:lossy-unix-strerror, r=thomcc
[rust.git] / src / tools / miri / tests / pass / fat_ptr.rs
1 // test that ordinary fat pointer operations work.
2
3 struct Wrapper<T: ?Sized>(u32, T);
4
5 struct FatPtrContainer<'a> {
6     ptr: &'a [u8],
7 }
8
9 fn fat_ptr_project(a: &Wrapper<[u8]>) -> &[u8] {
10     &a.1
11 }
12
13 fn fat_ptr_simple(a: &[u8]) -> &[u8] {
14     a
15 }
16
17 fn fat_ptr_via_local(a: &[u8]) -> &[u8] {
18     let x = a;
19     x
20 }
21
22 fn fat_ptr_from_struct(s: FatPtrContainer) -> &[u8] {
23     s.ptr
24 }
25
26 fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer {
27     FatPtrContainer { ptr: a }
28 }
29
30 fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) {
31     *b = a;
32 }
33
34 fn fat_ptr_constant() -> &'static str {
35     "HELLO"
36 }
37
38 fn main() {
39     let a = Wrapper(4, [7, 6, 5]);
40
41     let p = fat_ptr_project(&a);
42     let p = fat_ptr_simple(p);
43     let p = fat_ptr_via_local(p);
44     let p = fat_ptr_from_struct(fat_ptr_to_struct(p));
45
46     let mut target: &[u8] = &[42];
47     fat_ptr_store_to(p, &mut target);
48     assert_eq!(target, &a.1);
49
50     assert_eq!(fat_ptr_constant(), "HELLO");
51 }