From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/generator/auto-trait-regions.rs | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/ui/generator/auto-trait-regions.rs (limited to 'src/test/ui/generator/auto-trait-regions.rs') diff --git a/src/test/ui/generator/auto-trait-regions.rs b/src/test/ui/generator/auto-trait-regions.rs new file mode 100644 index 000000000..ea4b0d554 --- /dev/null +++ b/src/test/ui/generator/auto-trait-regions.rs @@ -0,0 +1,53 @@ +#![feature(generators)] +#![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 generator interiors so we can't match it in trait selection + let x: &'static _ = &OnlyFooIfStaticRef(No); + let gen = || { + 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 = || { + let x = x; + yield; + assert_foo(x); + }; + assert_foo(gen); // ok + + // Disallow impls which relates lifetimes in the generator interior + let gen = || { + 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