]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dynamically-sized-types/dst-deref-mut.rs
Rollup merge of #100861 - RalfJung:const-ice, r=oli-obk
[rust.git] / src / test / ui / dynamically-sized-types / dst-deref-mut.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, DerefMut};
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         panic!();
16     }
17 }
18
19 impl DerefMut for Arr {
20     fn deref_mut(&mut self) -> &mut [usize] {
21         &mut *self.ptr
22     }
23 }
24
25 pub fn foo(arr: &mut Arr) {
26     let x: &mut [usize] = &mut **arr;
27     assert_eq!(x[0], 1);
28     assert_eq!(x[1], 2);
29     assert_eq!(x[2], 3);
30 }
31
32 fn main() {
33     let mut a = Arr { ptr: Box::new([1, 2, 3]) };
34     foo(&mut a);
35 }