1 // Regression test for #52873. We used to ICE due to unexpected
2 // overflows when checking for "blanket impl inclusion".
4 use std::marker::PhantomData;
5 use std::cmp::Ordering;
6 use std::ops::{Add, Mul};
11 pub type U1 = UInt<UTerm, B1>;
21 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
31 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
47 impl NonZero for B1 {}
49 pub trait PrivatePow<Y, N> {
52 pub type PrivatePowOut<A, Y, N> = <A as PrivatePow<Y, N>>::Output;
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;
59 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
64 pub fn new() -> UTerm {
69 impl Unsigned for UTerm {
72 #[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Debug, Default)]
73 pub struct UInt<U, B> {
74 _marker: PhantomData<(U, B)>,
77 impl<U: Unsigned, B: Bit> UInt<U, B> {
79 pub fn new() -> UInt<U, B> {
86 impl<U: Unsigned, B: Bit> Unsigned for UInt<U, B> {
89 impl<U: Unsigned, B: Bit> NonZero for UInt<U, B> {}
91 impl Add<B0> for UTerm {
93 fn add(self, _: B0) -> Self::Output {
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 {
105 impl<U: Unsigned> Add<U> for UTerm {
107 fn add(self, _: U) -> Self::Output {
112 impl<U: Unsigned, B: Bit> Mul<B0> for UInt<U, B> {
114 fn mul(self, _: B0) -> Self::Output {
119 impl<U: Unsigned, B: Bit> Mul<B1> for UInt<U, B> {
120 type Output = UInt<U, B>;
121 fn mul(self, _: B1) -> Self::Output {
126 impl<U: Unsigned> Mul<U> for UTerm {
128 fn mul(self, _: U) -> Self::Output {
133 impl<Ul: Unsigned, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B0>
135 Ul: Mul<UInt<Ur, B>>,
137 type Output = UInt<Prod<Ul, UInt<Ur, B>>, B0>;
138 fn mul(self, _: UInt<Ur, B>) -> Self::Output {
147 impl<X: Unsigned, N: Unsigned> Pow<N> for X
149 X: PrivatePow<U1, N>,
151 type Output = PrivatePowOut<X, U1, N>;
154 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U0> for X {
158 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U1> for X
162 type Output = Prod<X, Y>;
165 impl<Y: Unsigned, U: Unsigned, B: Bit, X: Unsigned> PrivatePow<Y, UInt<UInt<U, B>, B0>> for X
168 Square<X>: PrivatePow<Y, UInt<U, B>>,
170 type Output = PrivatePowOut<Square<X>, Y, UInt<U, B>>;