-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add await_holding_invalid_type
lint
#8707
Conversation
changelog: [`await_holding_invalid_type`] This lint allows users to create a denylist of types which are not allowed to be held across await points. This is essentially a re-implementation of the language-level [`must_not_suspend` lint](rust-lang/rust#83310). That lint has a lot of work still to be done before it will reach Rust stable, and in the meantime there are a lot of types which can trip up developers if they are used improperly.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon. Please see the contribution instructions for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, I have but a few small suggestions.
let await_holding_invalid_types = conf.await_holding_invalid_types.clone(); | ||
store.register_late_pass(move || { | ||
Box::new(await_holding_invalid::AwaitHolding::new( | ||
await_holding_invalid_types.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await_holding_invalid_types.clone(), | |
await_holding_invalid_types, |
No need for double clone, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this initially but borrowck doesn't like it
error[E0507]: cannot move out of `await_holding_invalid_types`, a captured variable in an `Fn` closure
--> clippy_lints/src/lib.rs:519:88
|
518 | let await_holding_invalid_types = conf.await_holding_invalid_types.clone();
| --------------------------- captured outer variable
519 | store.register_late_pass(move || Box::new(await_holding_invalid::AwaitHolding::new(await_holding_invalid_types)));
| ----------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^--
| | |
| | move occurs because `await_holding_invalid_types` has type `std::vec::Vec<DisallowedType>`, which does not implement the `Copy` trait
| captured by this `Fn` closure
Co-authored-by: llogiq <bogusandre@gmail.com>
Co-authored-by: llogiq <bogusandre@gmail.com>
Co-authored-by: llogiq <bogusandre@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final request re the lint docs, otherwise this is ready to merge.
Thank you! ❤️ @bors r+ |
📌 Commit 0508685 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
changelog: [
await_holding_invalid_type
]This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level
must_not_suspend
lint. That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.
I originally implemented this specifically for
tracing::span::Entered
, until I discovered #8434 and read the commentary on that PR. Given this implementation is fully user configurable, doesn't tie clippy to any one particular crate, and introduces no additional dependencies, it seems more appropriate.