]> git.lizzy.rs Git - rust.git/commitdiff
Avoid complex diagnostics in snippets which contain newlines
authorYuki Okushi <huyuumi.dev@gmail.com>
Sat, 1 Aug 2020 16:29:21 +0000 (01:29 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Mon, 2 Nov 2020 06:53:58 +0000 (15:53 +0900)
src/test/ui/async-await/issue-70935-complex-spans.rs [new file with mode: 0644]
src/test/ui/async-await/issue-70935-complex-spans.stderr [new file with mode: 0644]

diff --git a/src/test/ui/async-await/issue-70935-complex-spans.rs b/src/test/ui/async-await/issue-70935-complex-spans.rs
new file mode 100644 (file)
index 0000000..2965a7e
--- /dev/null
@@ -0,0 +1,25 @@
+// edition:2018
+// #70935: Check if we do not emit snippet
+// with newlines which lead complex diagnostics.
+
+use std::future::Future;
+
+async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
+}
+
+fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send {
+    //~^ ERROR: future cannot be sent between threads safely
+    async move {
+        baz(|| async{
+            foo(tx.clone());
+        }).await;
+    }
+}
+
+fn bar(_s: impl Future + Send) {
+}
+
+fn main() {
+    let (tx, _rx) = std::sync::mpsc::channel();
+    bar(foo(tx));
+}
diff --git a/src/test/ui/async-await/issue-70935-complex-spans.stderr b/src/test/ui/async-await/issue-70935-complex-spans.stderr
new file mode 100644 (file)
index 0000000..d9ce038
--- /dev/null
@@ -0,0 +1,31 @@
+error: future cannot be sent between threads safely
+  --> $DIR/issue-70935-complex-spans.rs:10:45
+   |
+LL |   fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send {
+   |                                               ^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
+LL |
+LL | /     async move {
+LL | |         baz(|| async{
+LL | |             foo(tx.clone());
+LL | |         }).await;
+LL | |     }
+   | |_____- this returned value is of type `impl std::future::Future`
+   |
+   = help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<i32>`
+note: future is not `Send` as this value is used across an await
+  --> $DIR/issue-70935-complex-spans.rs:13:9
+   |
+LL |            baz(|| async{
+   |  __________^___-
+   | | _________|
+   | ||
+LL | ||             foo(tx.clone());
+LL | ||         }).await;
+   | ||         -      ^- value is later dropped here
+   | ||_________|______|
+   | |__________|      await occurs here, with value maybe used later
+   |            has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10 tx:&std::sync::mpsc::Sender<i32>]` which is not `Send`
+   = note: the return type of a function must have a statically known size
+
+error: aborting due to previous error
+