summaryrefslogtreecommitdiffstats
path: root/tests/ui/generator/print
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/generator/print
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/generator/print')
-rw-r--r--tests/ui/generator/print/generator-print-verbose-1.rs60
-rw-r--r--tests/ui/generator/print/generator-print-verbose-1.stderr62
-rw-r--r--tests/ui/generator/print/generator-print-verbose-2.rs24
-rw-r--r--tests/ui/generator/print/generator-print-verbose-2.stderr56
-rw-r--r--tests/ui/generator/print/generator-print-verbose-3.rs12
-rw-r--r--tests/ui/generator/print/generator-print-verbose-3.stderr19
6 files changed, 233 insertions, 0 deletions
diff --git a/tests/ui/generator/print/generator-print-verbose-1.rs b/tests/ui/generator/print/generator-print-verbose-1.rs
new file mode 100644
index 000000000..89124ad72
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-1.rs
@@ -0,0 +1,60 @@
+// compile-flags: -Zverbose
+
+// Same as: tests/ui/generator/issue-68112.stderr
+
+#![feature(generators, generator_trait)]
+
+use std::{
+ cell::RefCell,
+ sync::Arc,
+ pin::Pin,
+ ops::{Generator, GeneratorState},
+};
+
+pub struct Ready<T>(Option<T>);
+impl<T> Generator<()> for Ready<T> {
+ type Return = T;
+ type Yield = ();
+ fn resume(mut self: Pin<&mut Self>, _args: ()) -> GeneratorState<(), T> {
+ GeneratorState::Complete(self.0.take().unwrap())
+ }
+}
+pub fn make_gen1<T>(t: T) -> Ready<T> {
+ Ready(Some(t))
+}
+
+fn require_send(_: impl Send) {}
+
+fn make_non_send_generator() -> impl Generator<Return = Arc<RefCell<i32>>> {
+ make_gen1(Arc::new(RefCell::new(0)))
+}
+
+fn test1() {
+ let send_gen = || {
+ let _non_send_gen = make_non_send_generator();
+ yield;
+ };
+ require_send(send_gen);
+ //~^ ERROR generator cannot be sent between threads
+}
+
+pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
+ || {
+ yield;
+ t
+ }
+}
+fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
+ make_gen2(Arc::new(RefCell::new(0)))
+}
+
+fn test2() {
+ let send_gen = || {
+ let _non_send_gen = make_non_send_generator2();
+ yield;
+ };
+ require_send(send_gen);
+ //~^ ERROR `RefCell<i32>` cannot be shared between threads safely
+}
+
+fn main() {}
diff --git a/tests/ui/generator/print/generator-print-verbose-1.stderr b/tests/ui/generator/print/generator-print-verbose-1.stderr
new file mode 100644
index 000000000..ebf35be58
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-1.stderr
@@ -0,0 +1,62 @@
+error: generator cannot be sent between threads safely
+ --> $DIR/generator-print-verbose-1.rs:37:18
+ |
+LL | require_send(send_gen);
+ | ^^^^^^^^ generator is not `Send`
+ |
+ = help: the trait `Sync` is not implemented for `RefCell<i32>`
+note: generator is not `Send` as this value is used across a yield
+ --> $DIR/generator-print-verbose-1.rs:35:9
+ |
+LL | let _non_send_gen = make_non_send_generator();
+ | ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
+LL | yield;
+ | ^^^^^ yield occurs here, with `_non_send_gen` maybe used later
+LL | };
+ | - `_non_send_gen` is later dropped here
+note: required by a bound in `require_send`
+ --> $DIR/generator-print-verbose-1.rs:26:25
+ |
+LL | fn require_send(_: impl Send) {}
+ | ^^^^ required by this bound in `require_send`
+
+error[E0277]: `RefCell<i32>` cannot be shared between threads safely
+ --> $DIR/generator-print-verbose-1.rs:56:18
+ |
+LL | require_send(send_gen);
+ | ------------ ^^^^^^^^ `RefCell<i32>` cannot be shared between threads safely
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Sync` is not implemented for `RefCell<i32>`
+ = note: required for `Arc<RefCell<i32>>` to implement `Send`
+note: required because it's used within this generator
+ --> $DIR/generator-print-verbose-1.rs:42:5
+ |
+LL | || {
+ | ^^
+note: required because it appears within the type `Opaque(DefId(0:35 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [Arc<RefCell<i32>>])`
+ --> $DIR/generator-print-verbose-1.rs:41:30
+ |
+LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+note: required because it appears within the type `Opaque(DefId(0:36 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
+ --> $DIR/generator-print-verbose-1.rs:47:34
+ |
+LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: required because it captures the following types: `Opaque(DefId(0:36 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
+note: required because it's used within this generator
+ --> $DIR/generator-print-verbose-1.rs:52:20
+ |
+LL | let send_gen = || {
+ | ^^
+note: required by a bound in `require_send`
+ --> $DIR/generator-print-verbose-1.rs:26:25
+ |
+LL | fn require_send(_: impl Send) {}
+ | ^^^^ required by this bound in `require_send`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/generator/print/generator-print-verbose-2.rs b/tests/ui/generator/print/generator-print-verbose-2.rs
new file mode 100644
index 000000000..d914719cb
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-2.rs
@@ -0,0 +1,24 @@
+// compile-flags: -Zverbose
+
+// Same as test/ui/generator/not-send-sync.rs
+#![feature(generators)]
+
+use std::cell::Cell;
+
+fn main() {
+ fn assert_sync<T: Sync>(_: T) {}
+ fn assert_send<T: Send>(_: T) {}
+
+ assert_sync(|| {
+ //~^ ERROR: generator cannot be shared between threads safely
+ let a = Cell::new(2);
+ yield;
+ });
+
+ let a = Cell::new(2);
+ assert_send(|| {
+ //~^ ERROR: E0277
+ drop(&a);
+ yield;
+ });
+}
diff --git a/tests/ui/generator/print/generator-print-verbose-2.stderr b/tests/ui/generator/print/generator-print-verbose-2.stderr
new file mode 100644
index 000000000..909e49c38
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-2.stderr
@@ -0,0 +1,56 @@
+error[E0277]: `Cell<i32>` cannot be shared between threads safely
+ --> $DIR/generator-print-verbose-2.rs:19:17
+ |
+LL | assert_send(|| {
+ | _____-----------_^
+ | | |
+ | | required by a bound introduced by this call
+LL | |
+LL | | drop(&a);
+LL | | yield;
+LL | | });
+ | |_____^ `Cell<i32>` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `Cell<i32>`
+ = note: required for `&'_#4r Cell<i32>` to implement `Send`
+note: required because it's used within this generator
+ --> $DIR/generator-print-verbose-2.rs:19:17
+ |
+LL | assert_send(|| {
+ | ^^
+note: required by a bound in `assert_send`
+ --> $DIR/generator-print-verbose-2.rs:10:23
+ |
+LL | fn assert_send<T: Send>(_: T) {}
+ | ^^^^ required by this bound in `assert_send`
+
+error: generator cannot be shared between threads safely
+ --> $DIR/generator-print-verbose-2.rs:12:17
+ |
+LL | assert_sync(|| {
+ | _________________^
+LL | |
+LL | | let a = Cell::new(2);
+LL | | yield;
+LL | | });
+ | |_____^ generator is not `Sync`
+ |
+ = help: within `[main::{closure#0} upvar_tys=() {Cell<i32>, ()}]`, the trait `Sync` is not implemented for `Cell<i32>`
+note: generator is not `Sync` as this value is used across a yield
+ --> $DIR/generator-print-verbose-2.rs:15:9
+ |
+LL | let a = Cell::new(2);
+ | - has type `Cell<i32>` which is not `Sync`
+LL | yield;
+ | ^^^^^ yield occurs here, with `a` maybe used later
+LL | });
+ | - `a` is later dropped here
+note: required by a bound in `assert_sync`
+ --> $DIR/generator-print-verbose-2.rs:9:23
+ |
+LL | fn assert_sync<T: Sync>(_: T) {}
+ | ^^^^ required by this bound in `assert_sync`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/generator/print/generator-print-verbose-3.rs b/tests/ui/generator/print/generator-print-verbose-3.rs
new file mode 100644
index 000000000..8689539ec
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-3.rs
@@ -0,0 +1,12 @@
+// compile-flags: -Zverbose
+
+#![feature(generators, generator_trait)]
+
+fn main() {
+ let x = "Type mismatch test";
+ let generator :() = || {
+ //~^ ERROR mismatched types
+ yield 1i32;
+ return x
+ };
+}
diff --git a/tests/ui/generator/print/generator-print-verbose-3.stderr b/tests/ui/generator/print/generator-print-verbose-3.stderr
new file mode 100644
index 000000000..d15646259
--- /dev/null
+++ b/tests/ui/generator/print/generator-print-verbose-3.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/generator-print-verbose-3.rs:7:25
+ |
+LL | let generator :() = || {
+ | ____________________--___^
+ | | |
+ | | expected due to this
+LL | |
+LL | | yield 1i32;
+LL | | return x
+LL | | };
+ | |_____^ expected `()`, found generator
+ |
+ = note: expected unit type `()`
+ found generator `[main::{closure#0} upvar_tys=(unavailable)]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.