diff options
| author | Gus Wynn <guswynn@gmail.com> | 2021-09-27 08:43:30 -0700 |
|---|---|---|
| committer | Gus Wynn <guswynn@gmail.com> | 2021-09-27 08:43:30 -0700 |
| commit | 0f9c349834622fa337c8dab886af4041bcdad5bb (patch) | |
| tree | 260131df16901742d1b5056fea5b16c26ef1526f /src/test | |
| parent | ac8dd1b2f24dc62c962172b27433106b4e84dc62 (diff) | |
| download | rust-0f9c349834622fa337c8dab886af4041bcdad5bb.tar.gz rust-0f9c349834622fa337c8dab886af4041bcdad5bb.zip | |
lock types
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/lint/must_not_suspend/mutex.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/lint/must_not_suspend/mutex.stderr | 26 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/test/ui/lint/must_not_suspend/mutex.rs b/src/test/ui/lint/must_not_suspend/mutex.rs new file mode 100644 index 00000000000..7bb895e7d36 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/mutex.rs @@ -0,0 +1,13 @@ +// edition:2018 +#![feature(must_not_suspend)] +#![deny(must_not_suspend)] + +async fn other() {} + +pub async fn uhoh(m: std::sync::Mutex<()>) { + let _guard = m.lock().unwrap(); //~ ERROR `MutexGuard` held across + other().await; +} + +fn main() { +} diff --git a/src/test/ui/lint/must_not_suspend/mutex.stderr b/src/test/ui/lint/must_not_suspend/mutex.stderr new file mode 100644 index 00000000000..69638fc2010 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/mutex.stderr @@ -0,0 +1,26 @@ +error: `MutexGuard` held across a suspend point, but should not be + --> $DIR/mutex.rs:8:9 + | +LL | let _guard = m.lock().unwrap(); + | ^^^^^^ +LL | other().await; + | ------------- the value is held across this suspend point + | +note: the lint level is defined here + --> $DIR/mutex.rs:3:9 + | +LL | #![deny(must_not_suspend)] + | ^^^^^^^^^^^^^^^^ +note: Holding a MutexGuard across suspend points can cause deadlocks, delays, and cause Future's to not implement `Send` + --> $DIR/mutex.rs:8:9 + | +LL | let _guard = m.lock().unwrap(); + | ^^^^^^ +help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point + --> $DIR/mutex.rs:8:9 + | +LL | let _guard = m.lock().unwrap(); + | ^^^^^^ + +error: aborting due to previous error + |
