Auto merge of #88865 - guswynn:must_not_suspend, r=oli-obk
Implement `#[must_not_suspend]` implements #83310 Some notes on the impl: 1. The code that searches for the attribute on the ADT is basically copied from the `must_use` lint. It's not shared, as the logic did diverge 2. The RFC does specify that the attribute can be placed on fn's (and fn-like objects), like `must_use`. I think this is a direct copy from the `must_use` reference definition. This implementation does NOT support this, as I felt that ADT's (+ `impl Trait` + `dyn Trait`) cover the usecase's people actually want on the RFC, and adding an imp for the fn call case would be significantly harder. The `must_use` impl can do a single check at fn call stmt time, but `must_not_suspend` would need to answer the question: "for some value X with type T, find any fn call that COULD have produced this value". That would require significant changes to `generator_interior.rs`, and I would need mentorship on that. `@eholk` and I are discussing it. 3. `@estebank` do you know a way I can make the user-provided `reason` note pop out? right now it seems quite hidden Also, I am not sure if we should run perf on this r? `@nikomatsakis`
This commit is contained in:
commit
ce45663e14
27 changed files with 701 additions and 5 deletions
|
@ -314,6 +314,44 @@ declare_lint! {
|
|||
"imports that are never used"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
|
||||
/// (`.await`)
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(must_not_suspend)]
|
||||
///
|
||||
/// #[must_not_suspend]
|
||||
/// struct SyncThing {}
|
||||
///
|
||||
/// async fn yield_now() {}
|
||||
///
|
||||
/// pub async fn uhoh() {
|
||||
/// let guard = SyncThing {};
|
||||
/// yield_now().await;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// {{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)
|
||||
///
|
||||
pub MUST_NOT_SUSPEND,
|
||||
Warn,
|
||||
"use of a `#[must_not_suspend]` value across a yield point",
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `unused_extern_crates` lint guards against `extern crate` items
|
||||
/// that are never used.
|
||||
|
@ -2993,6 +3031,7 @@ declare_lint_pass! {
|
|||
CENUM_IMPL_DROP_CAST,
|
||||
CONST_EVALUATABLE_UNCHECKED,
|
||||
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
|
||||
MUST_NOT_SUSPEND,
|
||||
UNINHABITED_STATIC,
|
||||
FUNCTION_ITEM_REFERENCES,
|
||||
USELESS_DEPRECATED,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue