From 1e2feb98ee07200542598641b4204d3458e73d18 Mon Sep 17 00:00:00 2001 From: Gus Wynn Date: Mon, 11 Oct 2021 13:25:06 -0700 Subject: [PATCH 1/3] make must_not_suspend allow-by-default until edge cases are ironed out --- compiler/rustc_lint_defs/src/builtin.rs | 2 +- src/test/ui/lint/must_not_suspend/warn.rs | 1 + src/test/ui/lint/must_not_suspend/warn.stderr | 12 ++++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 5830ce26fea3f..dffb033b6b6bc 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -348,7 +348,7 @@ declare_lint! { /// `MutexGuard`'s) /// pub MUST_NOT_SUSPEND, - Warn, + Allow, "use of a `#[must_not_suspend]` value across a yield point", } diff --git a/src/test/ui/lint/must_not_suspend/warn.rs b/src/test/ui/lint/must_not_suspend/warn.rs index 50a696ba52322..7fdea66a23517 100644 --- a/src/test/ui/lint/must_not_suspend/warn.rs +++ b/src/test/ui/lint/must_not_suspend/warn.rs @@ -1,6 +1,7 @@ // edition:2018 // run-pass #![feature(must_not_suspend)] +#![warn(must_not_suspend)] #[must_not_suspend = "You gotta use Umm's, ya know?"] struct Umm { diff --git a/src/test/ui/lint/must_not_suspend/warn.stderr b/src/test/ui/lint/must_not_suspend/warn.stderr index 24f52275b430a..42374d4acac27 100644 --- a/src/test/ui/lint/must_not_suspend/warn.stderr +++ b/src/test/ui/lint/must_not_suspend/warn.stderr @@ -1,19 +1,23 @@ warning: `Umm` held across a suspend point, but should not be - --> $DIR/warn.rs:20:9 + --> $DIR/warn.rs:21:9 | LL | let _guard = bar(); | ^^^^^^ LL | other().await; | ------------- the value is held across this suspend point | - = note: `#[warn(must_not_suspend)]` on by default +note: the lint level is defined here + --> $DIR/warn.rs:4:9 + | +LL | #![warn(must_not_suspend)] + | ^^^^^^^^^^^^^^^^ note: You gotta use Umm's, ya know? - --> $DIR/warn.rs:20:9 + --> $DIR/warn.rs:21:9 | LL | let _guard = bar(); | ^^^^^^ help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point - --> $DIR/warn.rs:20:9 + --> $DIR/warn.rs:21:9 | LL | let _guard = bar(); | ^^^^^^ From d2766a9664e6be9765a60a7adb6e1beb452da92a Mon Sep 17 00:00:00 2001 From: Gus Wynn Date: Mon, 11 Oct 2021 14:21:58 -0700 Subject: [PATCH 2/3] ensure lint-docs build for allow-by-default must_not_suspend --- compiler/rustc_lint_defs/src/builtin.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index dffb033b6b6bc..1f1a4fbfd1bec 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -322,6 +322,7 @@ declare_lint! { /// /// ```rust /// #![feature(must_not_suspend)] + /// #![warn(must_not_suspend)] /// /// #[must_not_suspend] /// struct SyncThing {} From 7b95c7be01a76b503b22cdc37caab1589d7ddc01 Mon Sep 17 00:00:00 2001 From: Gus Wynn Date: Thu, 14 Oct 2021 10:04:21 -0700 Subject: [PATCH 3/3] add regression test for allow-by-default must_not_suspend --- .../ui/lint/must_not_suspend/issue-89562.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/ui/lint/must_not_suspend/issue-89562.rs diff --git a/src/test/ui/lint/must_not_suspend/issue-89562.rs b/src/test/ui/lint/must_not_suspend/issue-89562.rs new file mode 100644 index 0000000000000..acdb36fcdabf9 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/issue-89562.rs @@ -0,0 +1,19 @@ +// edition:2018 +// run-pass + +use std::sync::Mutex; + +// Copied from the issue. Allow-by-default for now, so run-pass +pub async fn foo() { + let foo = Mutex::new(1); + let lock = foo.lock().unwrap(); + + // Prevent mutex lock being held across `.await` point. + drop(lock); + + bar().await; +} + +async fn bar() {} + +fn main() {}