From 5c69a5d93af06f5290b8b6c2e57796e34cfa5e50 Mon Sep 17 00:00:00 2001 From: Ziru Niu Date: Tue, 30 May 2023 19:54:58 +0800 Subject: [PATCH] add tests in #111906 --- ...t-type-direct-with-earlybound-lifetime-2.rs | 9 +++++++++ ...pe-direct-with-earlybound-lifetime-2.stderr | 18 ++++++++++++++++++ ...t-type-direct-with-earlybound-lifetime-3.rs | 10 ++++++++++ ...t-type-direct-with-earlybound-lifetime-4.rs | 13 +++++++++++++ ...pe-direct-with-earlybound-lifetime-4.stderr | 14 ++++++++++++++ ...ait-type-direct-with-earlybound-lifetime.rs | 10 ++++++++++ 6 files changed, 74 insertions(+) create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.stderr create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-3.rs create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.stderr create mode 100644 tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime.rs diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs new file mode 100644 index 0000000000000..7250310a59cd7 --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs @@ -0,0 +1,9 @@ +#![allow(unconditional_recursion)] + +fn foo<'a: 'a>() -> impl Sized { + let _: *mut &'a () = foo::<'a>(); + //~^ ERROR + loop {} +} + +fn main() {} diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.stderr b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.stderr new file mode 100644 index 0000000000000..13f2b2114a765 --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.stderr @@ -0,0 +1,18 @@ +error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds + --> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs:4:12 + | +LL | fn foo<'a: 'a>() -> impl Sized { + | -- ---------- opaque type defined here + | | + | hidden type `*mut &'a ()` captures the lifetime `'a` as defined here +LL | let _: *mut &'a () = foo::<'a>(); + | ^^^^^^^^^^^ + | +help: to declare that `impl Sized` captures `'a`, you can add an explicit `'a` lifetime bound + | +LL | fn foo<'a: 'a>() -> impl Sized + 'a { + | ++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0700`. diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-3.rs b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-3.rs new file mode 100644 index 0000000000000..6257e87653f63 --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-3.rs @@ -0,0 +1,10 @@ +// check-pass + +#![allow(unconditional_recursion)] + +fn foo<'a: 'a>() -> impl Sized + 'a { + let _: *mut &'a () = foo::<'a>(); + loop {} +} + +fn main() {} diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs new file mode 100644 index 0000000000000..77578b60cddee --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs @@ -0,0 +1,13 @@ +#![allow(unconditional_recursion)] + +trait Trait<'a, 'b> {} +impl<'a, 'b, T> Trait<'a, 'b> for T {} + +fn foo<'a: 'a, 'b: 'b>() -> impl Trait<'a, 'b> { + let _: *mut &'a () = foo::<'a, 'b>(); + let _: *mut &'b () = foo::<'a, 'b>(); + //~^ ERROR + loop {} +} + +fn main() {} diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.stderr b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.stderr new file mode 100644 index 0000000000000..2fff3b796493f --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.stderr @@ -0,0 +1,14 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs:8:12 + | +LL | let _: *mut &'b () = foo::<'a, 'b>(); + | ^^^^^^^^^^^ expected `*mut &'a ()`, got `*mut &'b ()` + | +note: previous use here + --> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs:7:12 + | +LL | let _: *mut &'a () = foo::<'a, 'b>(); + | ^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime.rs b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime.rs new file mode 100644 index 0000000000000..7f15d4e6303f5 --- /dev/null +++ b/tests/ui/impl-trait/recursive/recursive-impl-trait-type-direct-with-earlybound-lifetime.rs @@ -0,0 +1,10 @@ +// check-pass + +#![allow(unconditional_recursion)] + +fn foo<'a: 'a>() -> impl Sized { + let _: () = foo::<'a>(); + loop {} +} + +fn main() {}