Static rustc_lint_defs::builtin::MUST_NOT_SUSPEND
source · pub static MUST_NOT_SUSPEND: &Lint
Expand description
The must_not_suspend
lint guards against values that shouldn’t be held across suspend points
(.await
)
Example
#![feature(must_not_suspend)]
#![warn(must_not_suspend)]
#[must_not_suspend]
struct SyncThing {}
async fn yield_now() {}
pub async fn uhoh() {
let guard = SyncThing {};
yield_now().await;
let _guard = guard;
}
{{produces}}
Explanation
The must_not_suspend
lint detects values that are marked with the #[must_not_suspend]
attribute being held across suspend points. A “suspend” point is usually a .await
in an async
function.
This attribute can be used to mark values that are semantically incorrect across suspends
(like certain types of timers), values that have async alternatives, and values that
regularly cause problems with the Send
-ness of async fn’s returned futures (like
MutexGuard
’s)