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: fix #[instrument(err)] with impl Trait return types #1236

Merged
merged 2 commits into from
Feb 11, 2021

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Feb 11, 2021

This backports PR #1233 to v0.1.x. This isn't just a simple cherry-pick
because the new tests in that branch use the v0.2.x module names, so
that had to be fixed. Otherwise, though, it's the same change, and I'll go
ahead and merge it when CI passes, since it was approved on master.

Motivation

Currently, using #[instrument(err)] on a function returning a Result
with an impl Trait in it results in a compiler error. This is because
we generate a type annotation on the closure in the function body that
contains the user function's actual body, and impl Trait isn't allowed
on types in local bindings, only on function parameters and return
types.

Solution

This branch fixes the issue by simply removing the return type
annotation from the closure. I've also added tests that break on master
for functions returning impl Trait, both with and without the err
argument.

Fixes #1227

Signed-off-by: Eliza Weisman eliza@buoyant.io

…1233)

## Motivation

Currently, using `#[instrument(err)]` on a function returning a `Result`
with an `impl Trait` in it results in a compiler error. This is because
we generate a type annotation on the closure in the function body that
contains the user function's actual body, and `impl Trait` isn't allowed
on types in local bindings, only on function parameters and return
types.

## Solution

This branch fixes the issue by simply removing the return type
annotation from the closure. I've also added tests that break on master
for functions returning `impl Trait`, both with and without the `err`
argument.

Fixes #1227

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw requested a review from a team as a code owner February 11, 2021 19:23
@hawkw hawkw self-assigned this Feb 11, 2021
@hawkw hawkw merged commit e1e3431 into v0.1.x Feb 11, 2021
@hawkw hawkw deleted the eliza/backport-1233 branch February 11, 2021 20:24
hawkw added a commit that referenced this pull request Feb 17, 2021
Fixed

- Compiler error when using `#[instrument(err)]` on functions which
  return `impl Trait` ([#1236])

[#1236]: #1236

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Feb 17, 2021
### Fixed

- Compiler error when using `#[instrument(err)]` on functions which
  return `impl Trait` ([#1236])

[#1236]: #1236

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Feb 17, 2021
Fixed

- **attributes**: Compiler error when using `#[instrument(err)]` on
  functions which return `impl Trait` ([#1236])
- Fixed broken match arms in event macros ([#1239])
- Documentation improvements ([#1232])

Thanks to @bkchr and @lfranke for contributing to this release!

[#1236]: #1236
[#1239]: #1239
[#1232]: #1232

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Feb 17, 2021
### Fixed

- **attributes**: Compiler error when using `#[instrument(err)]` on
  functions which return `impl Trait` ([#1236])
- Fixed broken match arms in event macros ([#1239])
- Documentation improvements ([#1232])

Thanks to @bkchr and @lfranke for contributing to this release!

[#1236]: #1236
[#1239]: #1239
[#1232]: #1232

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
### Fixed

- Compiler error when using `#[instrument(err)]` on functions which
  return `impl Trait` ([tokio-rs#1236])

[tokio-rs#1236]: tokio-rs#1236

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
### Fixed

- **attributes**: Compiler error when using `#[instrument(err)]` on
  functions which return `impl Trait` ([tokio-rs#1236])
- Fixed broken match arms in event macros ([tokio-rs#1239])
- Documentation improvements ([tokio-rs#1232])

Thanks to @bkchr and @lfranke for contributing to this release!

[tokio-rs#1236]: tokio-rs#1236
[tokio-rs#1239]: tokio-rs#1239
[tokio-rs#1232]: tokio-rs#1232

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
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.

None yet

1 participant