From ee948d99815b73359214f28a8f1eb69f3091a026 Mon Sep 17 00:00:00 2001 From: emlai Date: Sun, 17 Feb 2019 20:41:18 +0200 Subject: [PATCH] Add regression test for a specialization-related ICE (#39448) --- src/test/ui/specialization/issue-39448.rs | 50 +++++++++++++++++++ src/test/ui/specialization/issue-39448.stderr | 12 +++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/ui/specialization/issue-39448.rs create mode 100644 src/test/ui/specialization/issue-39448.stderr diff --git a/src/test/ui/specialization/issue-39448.rs b/src/test/ui/specialization/issue-39448.rs new file mode 100644 index 0000000000000..8ac6d8e9311fc --- /dev/null +++ b/src/test/ui/specialization/issue-39448.rs @@ -0,0 +1,50 @@ +#![feature(specialization)] + +// Regression test for a specialization-related ICE (#39448). + +trait A: Sized { + fn foo(self, _: Self) -> Self { + self + } +} + +impl A for u8 {} +impl A for u16 {} + +impl FromA for u16 { + fn from(x: u8) -> u16 { + x as u16 + } +} + +trait FromA { + fn from(T) -> Self; +} + +impl> FromA for U { + default fn from(x: T) -> Self { + ToA::to(x) + } +} + +trait ToA { + fn to(self) -> T; +} + +impl ToA for T +where + U: FromA, +{ + fn to(self) -> U { + U::from(self) + } +} + +#[allow(dead_code)] +fn foo(x: T, y: U) -> U { + x.foo(y.to()).to() //~ ERROR overflow evaluating the requirement +} + +fn main() { + let z = foo(8u8, 1u16); +} diff --git a/src/test/ui/specialization/issue-39448.stderr b/src/test/ui/specialization/issue-39448.stderr new file mode 100644 index 0000000000000..0b0fd2c4af591 --- /dev/null +++ b/src/test/ui/specialization/issue-39448.stderr @@ -0,0 +1,12 @@ +error[E0275]: overflow evaluating the requirement `T: FromA` + --> $DIR/issue-39448.rs:45:13 + | +LL | x.foo(y.to()).to() //~ ERROR overflow evaluating the requirement + | ^^ + | + = note: required because of the requirements on the impl of `FromA` for `T` + = note: required because of the requirements on the impl of `ToA` for `U` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0275`.