-
Notifications
You must be signed in to change notification settings - Fork 727
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
attributes: remove extra braces around async
blocks
#2090
Merged
hawkw
merged 3 commits into
tokio-rs:master
from
jarrodldavis:fix-extra-braces-from-instrument
Apr 25, 2022
Merged
attributes: remove extra braces around async
blocks
#2090
hawkw
merged 3 commits into
tokio-rs:master
from
jarrodldavis:fix-extra-braces-from-instrument
Apr 25, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jarrodldavis
requested review from
hawkw,
davidbarsky and
a team
as code owners
April 25, 2022 03:56
hawkw
approved these changes
Apr 25, 2022
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.
thanks for the fix, this looks great to me!
Comment on lines
+55
to
+69
// Reproduces https://github.com/tokio-rs/tracing/issues/1831 | ||
#[instrument] | ||
#[deny(unused_braces)] | ||
fn repro_1831() -> Pin<Box<dyn Future<Output = ()>>> { | ||
Box::pin(async move {}) | ||
} | ||
|
||
// This replicates the pattern used to implement async trait methods on nightly using the | ||
// `type_alias_impl_trait` feature | ||
#[instrument(ret, err)] | ||
#[deny(unused_braces)] | ||
#[allow(clippy::manual_async_fn)] | ||
fn repro_1831_2() -> impl Future<Output = Result<(), Infallible>> { | ||
async { Ok(()) } | ||
} |
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.
thanks for adding tests for this! <3
hawkw
pushed a commit
that referenced
this pull request
Apr 26, 2022
## Motivation When using an `async` block (as an alternative to `async fn`, e.g. when implementing a trait), `#[instrument]` adds extra braces around the wrapped `async` block. This causes `rustc` to emit an `unused_braces` lint in some cases (usually for single-line `async` blocks, as far as I can tell). See #1831 for an example. ## Solution Since the `async` block extracted by `AsyncInfo::from_fn` already has braces around its statements, there's no need to wrap it with additional braces. This updates `gen_block` to remove those extra braces when generating the code providing the value of `__tracing_instrument_future`. - [x] add repros for `unused_braces` issue - [x] remove extra braces from async blocks Fixes #1831
hawkw
pushed a commit
that referenced
this pull request
Apr 26, 2022
## Motivation When using an `async` block (as an alternative to `async fn`, e.g. when implementing a trait), `#[instrument]` adds extra braces around the wrapped `async` block. This causes `rustc` to emit an `unused_braces` lint in some cases (usually for single-line `async` blocks, as far as I can tell). See #1831 for an example. ## Solution Since the `async` block extracted by `AsyncInfo::from_fn` already has braces around its statements, there's no need to wrap it with additional braces. This updates `gen_block` to remove those extra braces when generating the code providing the value of `__tracing_instrument_future`. - [x] add repros for `unused_braces` issue - [x] remove extra braces from async blocks Fixes #1831
hawkw
pushed a commit
that referenced
this pull request
Apr 26, 2022
## Motivation When using an `async` block (as an alternative to `async fn`, e.g. when implementing a trait), `#[instrument]` adds extra braces around the wrapped `async` block. This causes `rustc` to emit an `unused_braces` lint in some cases (usually for single-line `async` blocks, as far as I can tell). See #1831 for an example. ## Solution Since the `async` block extracted by `AsyncInfo::from_fn` already has braces around its statements, there's no need to wrap it with additional braces. This updates `gen_block` to remove those extra braces when generating the code providing the value of `__tracing_instrument_future`. - [x] add repros for `unused_braces` issue - [x] remove extra braces from async blocks Fixes #1831
hawkw
added a commit
that referenced
this pull request
Apr 26, 2022
# 0.1.21 (April 26, 2022) This release adds support for setting explicit parent and follows-from spans in the `#[instrument]` attribute. ### Added - `#[instrument(follows_from = ...)]` argument for setting one or more follows-from span ([#2093]) - `#[instrument(parent = ...)]` argument for overriding the generated span's parent ([#2091]) ### Fixed - Extra braces around `async` blocks in expanded code (causes a Clippy warning) ([#2090]) - Broken documentation links ([#2068], [#2077]) Thanks to @jarrodldavis, @ben0x539, and new contributor @jswrenn for contributing to this release! [#2093]: #2093 [#2091]: #2091 [#2090]: #2090 [#2077]: #2077 [#2068]: #2068
hawkw
added a commit
that referenced
this pull request
Apr 27, 2022
# 0.1.21 (April 26, 2022) This release adds support for setting explicit parent and follows-from spans in the `#[instrument]` attribute. ### Added - `#[instrument(follows_from = ...)]` argument for setting one or more follows-from span ([#2093]) - `#[instrument(parent = ...)]` argument for overriding the generated span's parent ([#2091]) ### Fixed - Extra braces around `async` blocks in expanded code (causes a Clippy warning) ([#2090]) - Broken documentation links ([#2068], [#2077]) Thanks to @jarrodldavis, @ben0x539, and new contributor @jswrenn for contributing to this release! [#2093]: #2093 [#2091]: #2091 [#2090]: #2090 [#2077]: #2077 [#2068]: #2068
kaffarell
pushed a commit
to kaffarell/tracing
that referenced
this pull request
May 22, 2024
# 0.1.21 (April 26, 2022) This release adds support for setting explicit parent and follows-from spans in the `#[instrument]` attribute. ### Added - `#[instrument(follows_from = ...)]` argument for setting one or more follows-from span ([tokio-rs#2093]) - `#[instrument(parent = ...)]` argument for overriding the generated span's parent ([tokio-rs#2091]) ### Fixed - Extra braces around `async` blocks in expanded code (causes a Clippy warning) ([tokio-rs#2090]) - Broken documentation links ([tokio-rs#2068], [tokio-rs#2077]) Thanks to @jarrodldavis, @ben0x539, and new contributor @jswrenn for contributing to this release! [tokio-rs#2093]: tokio-rs#2093 [tokio-rs#2091]: tokio-rs#2091 [tokio-rs#2090]: tokio-rs#2090 [tokio-rs#2077]: tokio-rs#2077 [tokio-rs#2068]: tokio-rs#2068
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
unused_braces
issueFixes #1831
Motivation
When using an
async
block (as an alternative toasync fn
, e.g. when implementing a trait),#[instrument]
adds extra braces around the wrappedasync
block. This causesrustc
to emit anunused_braces
lint in some cases (usually for single-lineasync
blocks, as far as I can tell). See #1831 for an example.Solution
Since the
async
block extracted byAsyncInfo::from_fn
already has braces around its statements, there's no need to wrap it with additional braces. This updatesgen_block
to remove those extra braces when generating the code providing the value of__tracing_instrument_future
.