-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// edition:2018 | ||
|
||
use std::future::Future; | ||
use std::sync::Mutex; | ||
|
||
fn fake_spawn<F: Future + Send + 'static>(f: F) { } | ||
|
||
async fn wrong_mutex() { | ||
let m = Mutex::new(1); | ||
{ | ||
let mut guard = m.lock().unwrap(); | ||
(async { "right"; }).await; | ||
*guard += 1; | ||
} | ||
|
||
(async { "wrong"; }).await; | ||
} | ||
|
||
fn main() { | ||
fake_spawn(wrong_mutex()); //~ Error future cannot be sent between threads safely | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: future cannot be sent between threads safely | ||
--> $DIR/issue-71137.rs:20:3 | ||
| | ||
LL | fn fake_spawn<F: Future + Send + 'static>(f: F) { } | ||
| ---- required by this bound in `fake_spawn` | ||
... | ||
LL | fake_spawn(wrong_mutex()); | ||
| ^^^^^^^^^^ future returned by `wrong_mutex` is not `Send` | ||
| | ||
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, i32>` | ||
note: future is not `Send` as this value is used across an await | ||
--> $DIR/issue-71137.rs:12:5 | ||
| | ||
LL | let mut guard = m.lock().unwrap(); | ||
| --------- has type `std::sync::MutexGuard<'_, i32>` which is not `Send` | ||
LL | (async { "right"; }).await; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here, with `mut guard` maybe used later | ||
LL | *guard += 1; | ||
LL | } | ||
| - `mut guard` is later dropped here | ||
|
||
error: aborting due to previous error | ||
|