attributes: fix #[instrument(err)] with impl Trait return types
#1236
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.
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 aResultwith an
impl Traitin it results in a compiler error. This is becausewe generate a type annotation on the closure in the function body that
contains the user function's actual body, and
impl Traitisn't allowedon 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 theerrargument.
Fixes #1227
Signed-off-by: Eliza Weisman eliza@buoyant.io