Skip to content

Commit 4eb07ab

Browse files
committed
Improve span of non-Send async block error
1 parent cf5bc6e commit 4eb07ab

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
341341
ReturnType::Type(_, ret) => quote!(#ret),
342342
};
343343

344-
let box_pin = quote_spanned!(ret_ty.span()=>
344+
let box_pin = quote_spanned!(block.brace_token.span=>
345345
Box::pin(async move {
346346
let __ret: #ret_ty = {
347347
#(#decls)*

tests/ui/send-not-implemented.stderr

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@ note: future is not `Send` as this value is used across an await
2222
= note: required for the cast to the object type `dyn Future<Output = ()> + Send`
2323

2424
error: future cannot be sent between threads safely
25-
--> $DIR/send-not-implemented.rs:14:33
25+
--> $DIR/send-not-implemented.rs:14:38
2626
|
27-
14 | async fn test_ret(&self) -> bool {
28-
| ^^^^ future created by async block is not `Send`
27+
14 | async fn test_ret(&self) -> bool {
28+
| ______________________________________^
29+
15 | | let mutex = Mutex::new(());
30+
16 | | let _guard = mutex.lock().unwrap();
31+
17 | | f().await;
32+
18 | | true
33+
19 | | }
34+
| |_____^ future created by async block is not `Send`
2935
|
3036
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
3137
note: future is not `Send` as this value is used across an await
3238
--> $DIR/send-not-implemented.rs:17:9
3339
|
34-
14 | async fn test_ret(&self) -> bool {
35-
| - `_guard` is later dropped here
36-
15 | let mutex = Mutex::new(());
3740
16 | let _guard = mutex.lock().unwrap();
3841
| ------ has type `MutexGuard<'_, ()>` which is not `Send`
3942
17 | f().await;
4043
| ^^^^^^^^^ await occurs here, with `_guard` maybe used later
44+
18 | true
45+
19 | }
46+
| - `_guard` is later dropped here
4147
= note: required for the cast to the object type `dyn Future<Output = bool> + Send`

0 commit comments

Comments
 (0)