summaryrefslogtreecommitdiffstats
path: root/src/test/ui/generator/print
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/generator/print
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/generator/print')
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-1.rs60
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-1.stderr60
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-2.rs24
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-2.stderr44
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-3.rs12
-rw-r--r--src/test/ui/generator/print/generator-print-verbose-3.stderr19
6 files changed, 219 insertions, 0 deletions
diff --git a/src/test/ui/generator/print/generator-print-verbose-1.rs b/src/test/ui/generator/print/generator-print-verbose-1.rs
new file mode 100644
index 000000000..fe0687722
--- /dev/null
+++ b/src/test/ui/generator/print/generator-print-verbose-1.rs
@@ -0,0 +1,60 @@
+// compile-flags: -Zverbose
+
+// Same as: src/test/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/src/test/ui/generator/print/generator-print-verbose-1.stderr b/src/test/ui/generator/print/generator-print-verbose-1.stderr
new file mode 100644
index 000000000..5b61f1e8f
--- /dev/null
+++ b/src/test/ui/generator/print/generator-print-verbose-1.stderr
@@ -0,0 +1,60 @@
+error: generator cannot be sent between threads safely
+ --> $DIR/generator-print-verbose-1.rs:37:5
+ |
+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:5
+ |
+LL | require_send(send_gen);
+ | ^^^^^^^^^^^^ `RefCell<i32>` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `RefCell<i32>`
+ = note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
+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:39 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::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:42 ~ 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:42 ~ 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/src/test/ui/generator/print/generator-print-verbose-2.rs b/src/test/ui/generator/print/generator-print-verbose-2.rs
new file mode 100644
index 000000000..d914719cb
--- /dev/null
+++ b/src/test/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/src/test/ui/generator/print/generator-print-verbose-2.stderr b/src/test/ui/generator/print/generator-print-verbose-2.stderr
new file mode 100644
index 000000000..eb79d2e6e
--- /dev/null
+++ b/src/test/ui/generator/print/generator-print-verbose-2.stderr
@@ -0,0 +1,44 @@
+error[E0277]: `Cell<i32>` cannot be shared between threads safely
+ --> $DIR/generator-print-verbose-2.rs:19:5
+ |
+LL | assert_send(|| {
+ | ^^^^^^^^^^^ `Cell<i32>` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `Cell<i32>`
+ = note: required because of the requirements on the impl of `Send` for `&'_#4r Cell<i32>`
+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:5
+ |
+LL | assert_sync(|| {
+ | ^^^^^^^^^^^ 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/src/test/ui/generator/print/generator-print-verbose-3.rs b/src/test/ui/generator/print/generator-print-verbose-3.rs
new file mode 100644
index 000000000..8689539ec
--- /dev/null
+++ b/src/test/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/src/test/ui/generator/print/generator-print-verbose-3.stderr b/src/test/ui/generator/print/generator-print-verbose-3.stderr
new file mode 100644
index 000000000..d15646259
--- /dev/null
+++ b/src/test/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`.