From b37cdc67bef4de5dde9f5cffeb8f7a2592fdde4b Mon Sep 17 00:00:00 2001 From: Obei Sideg Date: Thu, 25 May 2023 15:43:41 +0300 Subject: [PATCH] Add test for RPIT defined with different hidden types with different substs --- .../multiple-defining-usages-in-body.rs | 12 +++++++++ .../multiple-defining-usages-in-body.stderr | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/ui/impl-trait/multiple-defining-usages-in-body.rs create mode 100644 tests/ui/impl-trait/multiple-defining-usages-in-body.stderr diff --git a/tests/ui/impl-trait/multiple-defining-usages-in-body.rs b/tests/ui/impl-trait/multiple-defining-usages-in-body.rs new file mode 100644 index 0000000000000..c3a6f09f86d93 --- /dev/null +++ b/tests/ui/impl-trait/multiple-defining-usages-in-body.rs @@ -0,0 +1,12 @@ +trait Trait {} +impl Trait for () {} + +fn foo() -> impl Trait { + //~^ WARN function cannot return without recursing [unconditional_recursion] + let a: T = foo::(); + //~^ ERROR concrete type differs from previous defining opaque type use + loop {} + let _: T = foo::(); +} + +fn main() {} diff --git a/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr b/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr new file mode 100644 index 0000000000000..06991749bfad1 --- /dev/null +++ b/tests/ui/impl-trait/multiple-defining-usages-in-body.stderr @@ -0,0 +1,26 @@ +warning: function cannot return without recursing + --> $DIR/multiple-defining-usages-in-body.rs:4:1 + | +LL | fn foo() -> impl Trait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing +LL | +LL | let a: T = foo::(); + | ------------- recursive call site + | + = help: a `loop` may express intention better if this is on purpose + = note: `#[warn(unconditional_recursion)]` on by default + +error: concrete type differs from previous defining opaque type use + --> $DIR/multiple-defining-usages-in-body.rs:6:16 + | +LL | let a: T = foo::(); + | ^^^^^^^^^^^^^ expected `U`, got `T` + | +note: previous use here + --> $DIR/multiple-defining-usages-in-body.rs:9:16 + | +LL | let _: T = foo::(); + | ^^^^^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted +