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_span_guard lint #1942

Closed
wants to merge 1 commit into from
Closed

Add await_holding_span_guard lint #1942

wants to merge 1 commit into from

Conversation

smoelius
Copy link

@davidbarsky

I noticed that rust-lang/rust-clippy#8434 was closed, and I wanted to make you aware of an alternative: you could package your lint as a Dylint library. This PR (which need not be merged) shows how you might do that.

As a demonstration, I tested the library on https://github.com/bevyengine/bevy/tree/98938a8555eb414ee5e9b023c45fe3b5f202edc8, and it got a hit.

Specifically, I added this to Bevy's top-level Cargo.toml:

[workspace.metadata.dylint]
libraries = [
    { git = "https://github.com/smoelius/tracing", branch = "await_holding_span_guard", pattern = "lints/await_holding_span_guard" },
]

Then, I ran:

cargo dylint --all -- --features=trace

And I got this:

warning: this Span guard is held across an 'await' point. Consider using the `.instrument()` combinator or the `.in_scope()` method instead
   --> crates/bevy_ecs/src/schedule/executor_parallel.rs:213:25
    |
213 |                     let system_guard = system_span.enter();
    |                         ^^^^^^^^^^^^
    |
    = note: `#[warn(await_holding_span_guard)]` on by default
note: these are all the await points this ref is held through
   --> crates/bevy_ecs/src/schedule/executor_parallel.rs:213:21
    |
213 | /                     let system_guard = system_span.enter();
214 | |                     unsafe { system.run_unsafe((), world) };
215 | |                     #[cfg(feature = "trace")]
216 | |                     drop(system_guard);
...   |
220 | |                         .unwrap_or_else(|error| unreachable!("{}", error));
221 | |                 };
    | |_________________^

warning: `bevy_ecs` (lib) generated 1 warning

Again, you don't have to merge this. I just wanted to make you aware of the possibility.

Cheers.

@smoelius smoelius requested review from hawkw, davidbarsky and a team as code owners February 19, 2022 13:09
@hawkw
Copy link
Member

hawkw commented Feb 21, 2022

Thanks, this is very cool --- I wasn't previously aware of the existence of Dylint. I'll have to look into this further!

@smoelius
Copy link
Author

smoelius commented Mar 7, 2022

If you choose not to publish this (here or elsewhere), then with your permission, I would like to include it in Dylint's examples directory.

There is no rush to make a decision, however.

@davidbarsky
Copy link
Member

davidbarsky commented Mar 16, 2022

If you choose not to publish this (here or elsewhere), then with your permission, I would like to include it in Dylint's examples directory.

I don't think we want to publish this inside of the tokio-rs/tracing repo (it's getting a bit unwieldy...), but if you'd add it as an example to Dylint, that'd be great. I'd also be happy to find a place to link to that example + lint.

Just to keep things a bit organized on tracing's end, I'll close this PR.

@smoelius
Copy link
Author

smoelius commented Mar 24, 2022

@davidbarsky Sorry for the slow response.

The lint is here. I tried to make clear that you are the author. Also, I tried to make minimal changes to your code, only what was needed to make it work in the Dylint repository. Please let me know if there is anything you would like changed.

To run the lint on a workspace, perform the following three steps:

  1. Install cargo-dylint and dylint-link:

    cargo install cargo-dylint dylint-link
  2. Add the following to the workspace's Cargo.toml file:

    [workspace.metadata.dylint]
    libraries = [
        { git = "https://github.com/trailofbits/dylint", pattern = "examples/await_holding_span_guard" },
    ]
  3. Run cargo-dylint:

    cargo dylint --all --workspace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants