diff --git a/tests/ui/traits/ice-normalize-erasing-regions-132767.rs b/tests/ui/traits/ice-normalize-erasing-regions-132767.rs new file mode 100644 index 0000000000000..b2366ab676ac2 --- /dev/null +++ b/tests/ui/traits/ice-normalize-erasing-regions-132767.rs @@ -0,0 +1,39 @@ +// Regression test for #132767 +// This used to ICE with "maybe try to call `try_normalize_erasing_regions`" +// when using associated types with fn pointers and impl Trait. +// Now it correctly reports a trait bound error. + +use std::hint::black_box; + +trait Func { + type Ret: Id; +} +trait Id { + type Assoc; +} +impl Id for i32 { + type Assoc = i32; +} +impl R, R: Id> Func for F { + type Ret = R; +} +fn bar() -> impl Copy + Id { + //~^ ERROR the trait bound `u32: Id` is not satisfied + 0u32 +} +struct Foo { + _func: T, + value: Option<<::Ret as Id>::Assoc>, +} +fn main() { + let mut fn_def = black_box(Foo { + _func: bar, + value: None, + }); + let fn_ptr = black_box(Foo { + _func: bar as fn() -> _, + value: None, + }); + fn_def.value = fn_ptr.value; + black_box(fn_def); +} diff --git a/tests/ui/traits/ice-normalize-erasing-regions-132767.stderr b/tests/ui/traits/ice-normalize-erasing-regions-132767.stderr new file mode 100644 index 0000000000000..12f4fdeabcb4d --- /dev/null +++ b/tests/ui/traits/ice-normalize-erasing-regions-132767.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `u32: Id` is not satisfied + --> $DIR/ice-normalize-erasing-regions-132767.rs:20:13 + | +LL | fn bar() -> impl Copy + Id { + | ^^^^^^^^^^^^^^ the trait `Id` is not implemented for `u32` +LL | +LL | 0u32 + | ---- return type was inferred to be `u32` here + | +help: the trait `Id` is implemented for `i32` + --> $DIR/ice-normalize-erasing-regions-132767.rs:14:1 + | +LL | impl Id for i32 { + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`.