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 {
109 unsafe { ::std::mem::uninitialized() }
113 impl<U: Unsigned, B: Bit> Mul<B0> for UInt<U, B> {
115 fn mul(self, _: B0) -> Self::Output {
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 {
127 impl<U: Unsigned> Mul<U> for UTerm {
129 fn mul(self, _: U) -> Self::Output {
134 impl<Ul: Unsigned, B: Bit, Ur: Unsigned> Mul<UInt<Ur, B>> for UInt<Ul, B0>
136 Ul: Mul<UInt<Ur, B>>,
138 type Output = UInt<Prod<Ul, UInt<Ur, B>>, B0>;
139 fn mul(self, _: UInt<Ur, B>) -> Self::Output {
140 unsafe { ::std::mem::uninitialized() }
148 impl<X: Unsigned, N: Unsigned> Pow<N> for X
150 X: PrivatePow<U1, N>,
152 type Output = PrivatePowOut<X, U1, N>;
155 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U0> for X {
159 impl<Y: Unsigned, X: Unsigned> PrivatePow<Y, U1> for X
163 type Output = Prod<X, Y>;
166 impl<Y: Unsigned, U: Unsigned, B: Bit, X: Unsigned> PrivatePow<Y, UInt<UInt<U, B>, B0>> for X
169 Square<X>: PrivatePow<Y, UInt<U, B>>,
171 type Output = PrivatePowOut<Square<X>, Y, UInt<U, B>>;