New lint disallowed_from_async#9857
Conversation
|
r? @Manishearth (rust-highfive has picked a reviewer for you, use r? to override) |
Hmm, we have a hard rule against lints of this kind (global analyses). The typical way to do lints like this without requiring a global analysis is by enforcing such functions all be annotated with some special annotation, but that gets messy quickly as well since you end up needing a lot of annotations everywhere (transitively). cc @rust-lang/clippy for thoughts |
|
Thanks @Manishearth. I guess an alternative would be for me to maintain this lint as a separate project. It seems there's some tooling for doing that in the form of Dylint: https://blog.trailofbits.com/2021/11/09/write-rust-lints-without-forking-clippy. |
|
☔ The latest upstream changes (presumably #9800) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I'm also not a fan of introducing global analysis into Clippy. This will open up a whole new thing that we need to maintain. I'm afraid that this will lead to a situation we currently have with |
|
It's also a major perf hazard. |
|
Ok, no worries! I'll close this PR and spin it out as a separate project. Suggesting we close #4427 as |
This is a prototype of a new lint for detecting "dangerous" function calls from async contexts (#4427). The motivation is two-fold:
asynccontext, 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
clippylint:rustc_serializein thetargetdirectory. 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-19compiler can be found in thedisallowed-from-async-oldbranch 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