]> git.lizzy.rs Git - rust.git/blob - tests/ui/const-generics/generic_const_exprs/issue-86710.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / const-generics / generic_const_exprs / issue-86710.rs
1 // build-pass
2
3 #![allow(incomplete_features)]
4 #![feature(generic_const_exprs)]
5
6 use std::marker::PhantomData;
7
8 fn main() {
9     let x = FooImpl::<BarImpl<1>> { phantom: PhantomData };
10     let _ = x.foo::<BarImpl<1>>();
11 }
12
13 trait Foo<T>
14 where
15     T: Bar,
16 {
17     fn foo<U>(&self)
18     where
19         T: Operation<U>,
20         <T as Operation<U>>::Output: Bar;
21 }
22
23 struct FooImpl<T>
24 where
25     T: Bar,
26 {
27     phantom: PhantomData<T>,
28 }
29
30 impl<T> Foo<T> for FooImpl<T>
31 where
32     T: Bar,
33 {
34     fn foo<U>(&self)
35     where
36         T: Operation<U>,
37         <T as Operation<U>>::Output: Bar,
38     {
39         <<T as Operation<U>>::Output as Bar>::error_occurs_here();
40     }
41 }
42
43 trait Bar {
44     fn error_occurs_here();
45 }
46
47 struct BarImpl<const N: usize>;
48
49 impl<const N: usize> Bar for BarImpl<N> {
50     fn error_occurs_here() {}
51 }
52
53 trait Operation<Rhs> {
54     type Output;
55 }
56
57 //// Part-A: This causes error.
58 impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N>
59 where
60     BarImpl<{ N + M }>: Sized,
61 {
62     type Output = BarImpl<{ N + M }>;
63 }
64
65 //// Part-B: This doesn't cause error.
66 // impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N> {
67 //     type Output = BarImpl<M>;
68 // }
69
70 //// Part-C: This also doesn't cause error.
71 // impl<const M: usize, const N: usize> Operation<BarImpl<M>> for BarImpl<N> {
72 //     type Output = BarImpl<{ M }>;
73 // }