summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-generics/issues/issue-83288.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/const-generics/issues/issue-83288.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/const-generics/issues/issue-83288.rs')
-rw-r--r--tests/ui/const-generics/issues/issue-83288.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/ui/const-generics/issues/issue-83288.rs b/tests/ui/const-generics/issues/issue-83288.rs
new file mode 100644
index 000000000..a24596d24
--- /dev/null
+++ b/tests/ui/const-generics/issues/issue-83288.rs
@@ -0,0 +1,69 @@
+// build-pass
+
+#![allow(incomplete_features)]
+#![feature(generic_const_exprs)]
+
+use std::{marker::PhantomData, ops::Mul};
+
+pub enum Nil {}
+pub struct Cons<T, L> {
+ _phantom: PhantomData<(T, L)>,
+}
+
+pub trait Indices<const N: usize> {
+ const RANK: usize;
+ const NUM_ELEMS: usize;
+}
+
+impl<const N: usize> Indices<N> for Nil {
+ const RANK: usize = 0;
+ const NUM_ELEMS: usize = 1;
+}
+
+impl<T, I: Indices<N>, const N: usize> Indices<N> for Cons<T, I> {
+ const RANK: usize = I::RANK + 1;
+ const NUM_ELEMS: usize = I::NUM_ELEMS * N;
+}
+
+pub trait Concat<J> {
+ type Output;
+}
+
+impl<J> Concat<J> for Nil {
+ type Output = J;
+}
+
+impl<T, I, J> Concat<J> for Cons<T, I>
+where
+ I: Concat<J>,
+{
+ type Output = Cons<T, <I as Concat<J>>::Output>;
+}
+
+pub struct Tensor<I: Indices<N>, const N: usize>
+where
+ [u8; I::NUM_ELEMS]: Sized,
+{
+ pub data: [u8; I::NUM_ELEMS],
+ _phantom: PhantomData<I>,
+}
+
+impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul<Tensor<J, N>> for Tensor<I, N>
+where
+ I: Concat<J>,
+ <I as Concat<J>>::Output: Indices<N>,
+ [u8; I::NUM_ELEMS]: Sized,
+ [u8; J::NUM_ELEMS]: Sized,
+ [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
+{
+ type Output = Tensor<<I as Concat<J>>::Output, N>;
+
+ fn mul(self, _rhs: Tensor<J, N>) -> Self::Output {
+ Tensor {
+ data: [0u8; <I as Concat<J>>::Output::NUM_ELEMS],
+ _phantom: PhantomData,
+ }
+ }
+}
+
+fn main() {}