Skip to content

Commit fd18e3f

Browse files
committed
Rollup merge of rust-lang#58545 - emlai:regression-test-for-39448, r=Centril
Add regression test for a specialization-related ICE (rust-lang#39448) Closes rust-lang#39448. This is my first time contributing, I hope I got everything right. :)
2 parents 717aa46 + ee948d9 commit fd18e3f

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0275]: overflow evaluating the requirement `T: FromA<U>`
2+
--> $DIR/issue-39448.rs:45:13
3+
|
4+
LL | x.foo(y.to()).to() //~ ERROR overflow evaluating the requirement
5+
| ^^
6+
|
7+
= note: required because of the requirements on the impl of `FromA<U>` for `T`
8+
= note: required because of the requirements on the impl of `ToA<T>` for `U`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)