From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/coroutine/auto-trait-regions.rs | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/ui/coroutine/auto-trait-regions.rs (limited to 'tests/ui/coroutine/auto-trait-regions.rs') diff --git a/tests/ui/coroutine/auto-trait-regions.rs b/tests/ui/coroutine/auto-trait-regions.rs new file mode 100644 index 000000000..5fce70e8e --- /dev/null +++ b/tests/ui/coroutine/auto-trait-regions.rs @@ -0,0 +1,53 @@ +#![feature(coroutines)] +#![feature(auto_traits)] +#![feature(negative_impls)] + +auto trait Foo {} + +struct No; + +impl !Foo for No {} + +struct A<'a, 'b>(&'a mut bool, &'b mut bool, No); + +impl<'a, 'b: 'a> Foo for A<'a, 'b> {} + +struct OnlyFooIfStaticRef(No); +impl Foo for &'static OnlyFooIfStaticRef {} + +struct OnlyFooIfRef(No); +impl<'a> Foo for &'a OnlyFooIfRef {} + +fn assert_foo(f: T) {} + +fn main() { + // Make sure 'static is erased for coroutine interiors so we can't match it in trait selection + let x: &'static _ = &OnlyFooIfStaticRef(No); + let gen = move || { + let x = x; + yield; + assert_foo(x); + }; + assert_foo(gen); + //~^ ERROR implementation of `Foo` is not general enough + + // Allow impls which matches any lifetime + let x = &OnlyFooIfRef(No); + let gen = move || { + let x = x; + yield; + assert_foo(x); + }; + assert_foo(gen); // ok + + // Disallow impls which relates lifetimes in the coroutine interior + let gen = move || { + let a = A(&mut true, &mut true, No); + //~^ temporary value dropped while borrowed + //~| temporary value dropped while borrowed + yield; + assert_foo(a); + }; + assert_foo(gen); + //~^ ERROR not general enough +} -- cgit v1.2.3