]> git.lizzy.rs Git - rust.git/blob - src/test/rustdoc/issue-52873.rs
Rollup merge of #62158 - christianpoveda:ecx-memory-extra, r=RalfJung
[rust.git] / src / test / rustdoc / issue-52873.rs
1 // Regression test for #52873. We used to ICE due to unexpected
2 // overflows when checking for "blanket impl inclusion".
3
4 use std::marker::PhantomData;
5 use std::cmp::Ordering;
6 use std::ops::{Add, Mul};
7
8 pub type True = B1;
9 pub type False = B0;
10 pub type U0 = UTerm;
11 pub type U1 = UInt<UTerm, B1>;
12
13 pub trait NonZero {}
14
15 pub trait Bit {
16 }
17
18 pub trait Unsigned {
19 }
20
21 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
22 pub struct B0;
23
24 impl B0 {
25     #[inline]
26     pub fn new() -> B0 {
27         B0
28     }
29 }
30
31 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
32 pub struct B1;
33
34 impl B1 {
35     #[inline]
36     pub fn new() -> B1 {
37         B1
38     }
39 }
40
41 impl Bit for B0 {
42 }
43
44 impl Bit for B1 {
45 }
46
47 impl NonZero for B1 {}
48
49 pub trait PrivatePow<Y, N> {
50     type Output;
51 }
52 pub type PrivatePowOut<A, Y, N> = <A as PrivatePow<Y, N>>::Output;
53
54 pub type Add1<A> = <A as Add<::B1>>::Output;
55 pub type Prod<A, B> = <A as Mul<B>>::Output;
56 pub type Square<A> = <A as Mul>::Output;
57 pub type Sum<A, B> = <A as Add<B>>::Output;
58
59 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
60 pub struct UTerm;
61
62 impl UTerm {
63     #[inline]
64     pub fn new() -> UTerm {
65         UTerm
66     }
67 }
68
69 impl Unsigned for UTerm {
70 }
71
72 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
73 pub struct UInt<U, B> {
74     _marker: PhantomData<(U, B)>,
75 }
76
77 impl<U: Unsigned, B: Bit> UInt<U, B> {
78     #[inline]
79     pub fn new() -> UInt<U, B> {
80         UInt {
81             _marker: PhantomData,
82         }
83     }
84 }
85
86 impl<U: Unsigned, B: Bit> Unsigned for UInt<U, B> {
87 }
88
89 impl<U: Unsigned, B: Bit> NonZero for UInt<U, B> {}
90
91 impl Add<B0> for UTerm {
92     type Output = UTerm;
93     fn add(self, _: B0) -> Self::Output {
94         UTerm
95     }
96 }
97
98 impl<U: Unsigned, B: Bit> Add<B0> for UInt<U, B> {
99     type Output = UInt<U, B>;
100     fn add(self, _: B0) -> Self::Output {
101         UInt::new()
102     }
103 }
104
105 impl<U: Unsigned> Add<U> for UTerm {
106     type Output = U;
107     fn add(self, _: U) -> Self::Output {
108         #[allow(deprecated)]
109         unsafe { ::std::mem::uninitialized() }
110     }
111 }
112
113 impl<U: Unsigned, B: Bit> Mul<B0> for UInt<U, B> {
114     type Output = UTerm;
115     fn mul(self, _: B0) -> Self::Output {
116         UTerm
117     }
118 }
119
120 impl<U: Unsigned, B: Bit> Mul<B1> for UInt<U, B> {
121     type Output = UInt<U, B>;
122     fn mul(self, _: B1) -> Self::Output {
123         UInt::new()
124     }
125 }
126
127 impl<U: Unsigned> Mul<U> for UTerm {
128     type Output = UTerm;
129     fn mul(self, _: U) -> Self::Output {
130         UTerm
131     }
132 }
133
134 impl<Ul: Unsigned, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B0>
135 where
136     Ul: Mul<UInt<Ur, B>>,
137 {
138     type Output = UInt<Prod<Ul, UInt<Ur, B>>, B0>;
139     fn mul(self, _: UInt<Ur, B>) -> Self::Output {
140         unsafe { ::std::mem::uninitialized() }
141     }
142 }
143
144 pub trait Pow<Exp> {
145     type Output;
146 }
147
148 impl<X: Unsigned, N: Unsigned> Pow<N> for X
149 where
150     X: PrivatePow<U1, N>,
151 {
152     type Output = PrivatePowOut<X, U1, N>;
153 }
154
155 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U0> for X {
156     type Output = Y;
157 }
158
159 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U1> for X
160 where
161     X: Mul<Y>,
162 {
163     type Output = Prod<X, Y>;
164 }
165
166 impl<Y: Unsigned, U: Unsigned, B: Bit, X: Unsigned> PrivatePow<Y, UInt<UInt<U, B>, B0>> for X
167 where
168     X: Mul,
169     Square<X>: PrivatePow<Y, UInt<U, B>>,
170 {
171     type Output = PrivatePowOut<Square<X>, Y, UInt<U, B>>;
172 }