Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make must_not_suspend allow-by-default until edge cases are ironed out #89787

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ declare_lint! {
///
/// ```rust
/// #![feature(must_not_suspend)]
/// #![warn(must_not_suspend)]
///
/// #[must_not_suspend]
/// struct SyncThing {}
Expand All @@ -348,7 +349,7 @@ declare_lint! {
/// `MutexGuard`'s)
///
pub MUST_NOT_SUSPEND,
Warn,
Allow,
"use of a `#[must_not_suspend]` value across a yield point",
}

Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/lint/must_not_suspend/issue-89562.rs
Original file line number Diff line number Diff line change
@@ -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() {}
1 change: 1 addition & 0 deletions src/test/ui/lint/must_not_suspend/warn.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/lint/must_not_suspend/warn.stderr
Original file line number Diff line number Diff line change
@@ -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();
| ^^^^^^
Expand Down