New lint disallowed_from_async
#9857
Closed
+792
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a prototype of a new lint for detecting "dangerous" function calls from async contexts (#4427). The motivation is two-fold:
async
context, e.g.tokio::runtime::Handle::block_on
.The way the lint works currently is by defining two lists of relevant functions: disallowed methods and insulating wrapper methods. The disallowed methods are a user-supplied list of methods which can't be called from an async context unless they are insulated by one of the wrapper methods. The classic pair is
block_on
(disallowed) andspawn_blocking
(wrapper) as in:(for a more comprehensive list see the configuration for
lighthouse
)I found the implementation quite challenging because it seems to me unlike any existing
clippy
lint:rustc_serialize
in thetarget
directory. I'm not sure that the location I chose to place these files is sensible.Additionally since writing this lint a few months ago it has bitrotted, and this branch currently ICEs with an error similar to rust-lang/rust#103480:
A working version that still compiles with the older
nightly-2022-05-19
compiler can be found in thedisallowed-from-async-old
branch on my fork: https://github.com/michaelsproul/rust-clippy/tree/disallowed-from-async-old.Fixes #4427
changelog: [
disallowed_from_async
]: add new lint for disallowing function calls from async contexts