]> git.proxmox.com Git - rustc.git/blob - src/test/ui/specialization/issue-39448.rs
New upstream version 1.34.2+dfsg1
[rustc.git] / src / test / ui / specialization / issue-39448.rs
1 #![feature(specialization)]
2
3 // Regression test for a specialization-related ICE (#39448).
4
5 trait A: Sized {
6 fn foo(self, _: Self) -> Self {
7 self
8 }
9 }
10
11 impl A for u8 {}
12 impl A for u16 {}
13
14 impl FromA<u8> for u16 {
15 fn from(x: u8) -> u16 {
16 x as u16
17 }
18 }
19
20 trait FromA<T> {
21 fn from(T) -> Self;
22 }
23
24 impl<T: A, U: A + FromA<T>> FromA<T> for U {
25 default fn from(x: T) -> Self {
26 ToA::to(x)
27 }
28 }
29
30 trait ToA<T> {
31 fn to(self) -> T;
32 }
33
34 impl<T, U> ToA<U> for T
35 where
36 U: FromA<T>,
37 {
38 fn to(self) -> U {
39 U::from(self)
40 }
41 }
42
43 #[allow(dead_code)]
44 fn foo<T: A, U: A>(x: T, y: U) -> U {
45 x.foo(y.to()).to() //~ ERROR overflow evaluating the requirement
46 }
47
48 fn main() {
49 let z = foo(8u8, 1u16);
50 }