summaryrefslogtreecommitdiffstats
path: root/tests/ui/coroutine/auto-trait-regions.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/ui/coroutine/auto-trait-regions.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/coroutine/auto-trait-regions.rs')
-rw-r--r--tests/ui/coroutine/auto-trait-regions.rs53
1 files changed, 53 insertions, 0 deletions
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<T: 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
+}