-
Notifications
You must be signed in to change notification settings - Fork 761
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
instrument
attribute incompatible with inner attributes inside function
#2294
Comments
Thanks for the report, it definitely should be possible to use inner attributes! My guess is that the issue is because To fix this, we would need to handle the case where the function body begins with inner attributes by capturing them separately and inserting them before the code added by |
This would probably be a fairly straightforward fix for a new contributor to |
I updated the code to parse out the inner attributes fron the function body first and that wasn't too bad. I couldn't keep the `From<&'a ItemFn>` impl for `MaybeItemFnRef` due to lifetime issues though, so now it's `impl TryFrom<ItemFn> for MaybeItemFn`. Fixes: tokio-rs#2294
## Motivation When the `instrument` attribute is used on a function with inner attributes, the proc macro generates code above the attributes within the function block that causes compilation errors. These should be parsed out separately and handled. Fixes #2294 ## Solution I updated `MaybeItemFn` and `MaybeItemFnRef` to so they hold both the outer and inner attributes for the instrumented function and updated the codegen to inlcude them in the appropriate locations. I couldn't preserve the existing implementation of `From<&'_ ItemFn> for MaybeItemFnRef<'_, Box<Block>>`, because it is now necessary to separate the inner and outer attributes of the `ItemFn` into two separate `Vec`s. That implementation was replaced with a `From<ItemFn> for MaybeItemFn`, which uses `Iterator::partition` to separate out the inner and outer attributes. Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Bug Report
Version
Platform
Linux rust 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Description
This works without the
instrument
macro and it seems like it should be reasonable forinstrument
to support.https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9c6afbe0ad161308d88f9cf02dfd1178
The text was updated successfully, but these errors were encountered: