Skip to content

Commit c269525

Browse files
committed
Avoid complex diagnostics in snippets which contain newlines
1 parent d8ef0d7 commit c269525

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// edition:2018
2+
// #70935: Check if we do not emit snippet
3+
// with newlines which lead complex diagnostics.
4+
5+
use std::future::Future;
6+
7+
async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
8+
}
9+
10+
fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send {
11+
//~^ ERROR: future cannot be sent between threads safely
12+
async move {
13+
baz(|| async{
14+
foo(tx.clone());
15+
}).await;
16+
}
17+
}
18+
19+
fn bar(_s: impl Future + Send) {
20+
}
21+
22+
fn main() {
23+
let (tx, _rx) = std::sync::mpsc::channel();
24+
bar(foo(tx));
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: future cannot be sent between threads safely
2+
--> $DIR/issue-70935-complex-spans.rs:10:45
3+
|
4+
LL | fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send {
5+
| ^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
6+
LL |
7+
LL | / async move {
8+
LL | | baz(|| async{
9+
LL | | foo(tx.clone());
10+
LL | | }).await;
11+
LL | | }
12+
| |_____- this returned value is of type `impl std::future::Future`
13+
|
14+
= help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Sender<i32>`
15+
note: future is not `Send` as this value is used across an await
16+
--> $DIR/issue-70935-complex-spans.rs:13:9
17+
|
18+
LL | baz(|| async{
19+
| __________^___-
20+
| | _________|
21+
| ||
22+
LL | || foo(tx.clone());
23+
LL | || }).await;
24+
| || - ^- value is later dropped here
25+
| ||_________|______|
26+
| |__________| await occurs here, with value maybe used later
27+
| has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10 tx:&std::sync::mpsc::Sender<i32>]` which is not `Send`
28+
= note: the return type of a function must have a statically known size
29+
30+
error: aborting due to previous error
31+

0 commit comments

Comments
 (0)