Skip to content
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

Merged
merged 10 commits into from
Apr 18, 2022

Conversation

lilymara-onesignal
Copy link
Contributor

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.

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.
@rust-highfive
Copy link

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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 15, 2022
Copy link
Contributor

@llogiq llogiq left a 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.

clippy_lints/src/await_holding_invalid.rs Outdated Show resolved Hide resolved
clippy_lints/src/await_holding_invalid.rs Outdated Show resolved Hide resolved
clippy_lints/src/await_holding_invalid.rs Outdated Show resolved Hide resolved
clippy_lints/src/await_holding_invalid.rs Outdated Show resolved Hide resolved
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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await_holding_invalid_types.clone(),
await_holding_invalid_types,

No need for double clone, right?

Copy link
Contributor Author

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

lilymara-onesignal and others added 4 commits April 18, 2022 10:31
Co-authored-by: llogiq <bogusandre@gmail.com>
Co-authored-by: llogiq <bogusandre@gmail.com>
Co-authored-by: llogiq <bogusandre@gmail.com>
Copy link
Contributor

@llogiq llogiq left a 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.

clippy_lints/src/await_holding_invalid.rs Show resolved Hide resolved
@llogiq
Copy link
Contributor

llogiq commented Apr 18, 2022

Thank you! ❤️

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 18, 2022

📌 Commit 0508685 has been approved by llogiq

@bors
Copy link
Collaborator

bors commented Apr 18, 2022

⌛ Testing commit 0508685 with merge cbdf17c...

@bors
Copy link
Collaborator

bors commented Apr 18, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing cbdf17c to master...

@bors bors merged commit cbdf17c into rust-lang:master Apr 18, 2022
@lilymara-onesignal lilymara-onesignal deleted the await-invalid-types branch April 18, 2022 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants