]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dynamically-sized-types/dst-deref.rs
Auto merge of #99028 - tmiasko:inline, r=estebank
[rust.git] / src / test / ui / dynamically-sized-types / dst-deref.rs
1 // run-pass
2 // Test that a custom deref with a fat pointer return type does not ICE
3
4
5 use std::ops::Deref;
6
7 pub struct Arr {
8     ptr: Box<[usize]>
9 }
10
11 impl Deref for Arr {
12     type Target = [usize];
13
14     fn deref(&self) -> &[usize] {
15         &*self.ptr
16     }
17 }
18
19 pub fn foo(arr: &Arr) {
20     assert_eq!(arr.len(), 3);
21     let x: &[usize] = &**arr;
22     assert_eq!(x[0], 1);
23     assert_eq!(x[1], 2);
24     assert_eq!(x[2], 3);
25 }
26
27 fn main() {
28     let a = Arr { ptr: Box::new([1, 2, 3]) };
29     foo(&a);
30 }