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

attributes: remove extra braces around async blocks #2090

Merged
merged 3 commits into from
Apr 25, 2022
Merged

attributes: remove extra braces around async blocks #2090

merged 3 commits into from
Apr 25, 2022

Conversation

jarrodldavis
Copy link
Contributor

  • add repros for unused_braces issue
  • remove extra braces from async blocks

Fixes #1831

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.

@jarrodldavis jarrodldavis requested review from hawkw, davidbarsky and a team as code owners April 25, 2022 03:56
Copy link
Member

@hawkw hawkw left a 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(()) }
}
Copy link
Member

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 hawkw merged commit 839bd36 into tokio-rs:master Apr 25, 2022
@jarrodldavis jarrodldavis deleted the fix-extra-braces-from-instrument branch April 25, 2022 23:04
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[instrument] on a fn returning Pin<Box<dyn Future>> leads to bogus unused_braces lint
2 participants