|
| 1 | +//@ compile-flags: -Znext-solver |
| 2 | +//@ check-pass |
| 3 | + |
| 4 | +// Regression test for trait-system-refactor-initiative#105. We previously encountered |
| 5 | +// an ICE in typenum as `forced_ambiguity` failed. While this test no longer causes |
| 6 | +// `forced_ambiguity` to error, we still want to use it as a regression test. |
| 7 | + |
| 8 | +pub struct UInt<U, B> { |
| 9 | + _msb: U, |
| 10 | + _lsb: B, |
| 11 | +} |
| 12 | +pub struct B1; |
| 13 | +pub trait Sub<Rhs> { |
| 14 | + type Output; |
| 15 | +} |
| 16 | +impl<U, B> Sub<B1> for UInt<UInt<U, B>, B1> { |
| 17 | + type Output = (); |
| 18 | +} |
| 19 | +impl<U> Sub<B1> for UInt<U, ()> |
| 20 | +where |
| 21 | + U: Sub<B1>, |
| 22 | + U::Output: Send, |
| 23 | +{ |
| 24 | + type Output = (); |
| 25 | +} |
| 26 | + |
| 27 | +pub trait Op<N, R, I> { |
| 28 | + fn op(&self) { |
| 29 | + unimplemented!() |
| 30 | + } |
| 31 | +} |
| 32 | +trait OpIf<N, R, I> {} |
| 33 | + |
| 34 | +impl<N, Ur, Br, I> Op<N, UInt<Ur, Br>, I> for () |
| 35 | +where |
| 36 | + N: Sub<I>, |
| 37 | + (): OpIf<N, UInt<UInt<Ur, Br>, N::Output>, I>, |
| 38 | +{ |
| 39 | +} |
| 40 | +impl<N, R, Ui, Bi> OpIf<N, R, UInt<Ui, Bi>> for () |
| 41 | +where |
| 42 | + UInt<Ui, Bi>: Sub<B1>, |
| 43 | + (): Op<N, R, <UInt<Ui, Bi> as Sub<B1>>::Output>, |
| 44 | +{ |
| 45 | +} |
| 46 | +impl<N, R> OpIf<N, R, ()> for () where R: Sub<N> {} |
| 47 | + |
| 48 | +pub trait Compute { |
| 49 | + type Output; |
| 50 | +} |
| 51 | + |
| 52 | +pub fn repro<Ul, Bl>() |
| 53 | +where |
| 54 | + UInt<Ul, Bl>: Compute, |
| 55 | + <UInt<Ul, Bl> as Compute>::Output: Sub<B1>, |
| 56 | + (): Op<UInt<(), Bl>, (), ()>, |
| 57 | +{ |
| 58 | + ().op(); |
| 59 | +} |
| 60 | +fn main() {} |
0 commit comments