]> git.lizzy.rs Git - rust.git/blob - tests/ui/const-generics/issues/issue-83288.rs
Auto merge of #106711 - albertlarsan68:use-ci-llvm-when-lld, r=jyn514
[rust.git] / tests / ui / const-generics / issues / issue-83288.rs
1 // build-pass
2
3 #![allow(incomplete_features)]
4 #![feature(generic_const_exprs)]
5
6 use std::{marker::PhantomData, ops::Mul};
7
8 pub enum Nil {}
9 pub struct Cons<T, L> {
10     _phantom: PhantomData<(T, L)>,
11 }
12
13 pub trait Indices<const N: usize> {
14     const RANK: usize;
15     const NUM_ELEMS: usize;
16 }
17
18 impl<const N: usize> Indices<N> for Nil {
19     const RANK: usize = 0;
20     const NUM_ELEMS: usize = 1;
21 }
22
23 impl<T, I: Indices<N>, const N: usize> Indices<N> for Cons<T, I> {
24     const RANK: usize = I::RANK + 1;
25     const NUM_ELEMS: usize = I::NUM_ELEMS * N;
26 }
27
28 pub trait Concat<J> {
29     type Output;
30 }
31
32 impl<J> Concat<J> for Nil {
33     type Output = J;
34 }
35
36 impl<T, I, J> Concat<J> for Cons<T, I>
37 where
38     I: Concat<J>,
39 {
40     type Output = Cons<T, <I as Concat<J>>::Output>;
41 }
42
43 pub struct Tensor<I: Indices<N>, const N: usize>
44 where
45     [u8; I::NUM_ELEMS]: Sized,
46 {
47     pub data: [u8; I::NUM_ELEMS],
48     _phantom: PhantomData<I>,
49 }
50
51 impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul<Tensor<J, N>> for Tensor<I, N>
52 where
53     I: Concat<J>,
54     <I as Concat<J>>::Output: Indices<N>,
55     [u8; I::NUM_ELEMS]: Sized,
56     [u8; J::NUM_ELEMS]: Sized,
57     [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
58 {
59     type Output = Tensor<<I as Concat<J>>::Output, N>;
60
61     fn mul(self, _rhs: Tensor<J, N>) -> Self::Output {
62         Tensor {
63             data: [0u8; <I as Concat<J>>::Output::NUM_ELEMS],
64             _phantom: PhantomData,
65         }
66     }
67 }
68
69 fn main() {}