-
Notifications
You must be signed in to change notification settings - Fork 726
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: speculatively expand when parsing fails #1634
Conversation
Thanks for opening the PR! I converted this to a draft while it's a work in progress. Feel free to mark it as "ready for review" once you think the implementation is ready. |
I haven't had a chance to actually look closely at either PR yet, but It might be worth comparing this approach to that branch? |
I'm also not sure about the performance implications of cloning a Looking at the Changing this branch to use I don't immediately know whether or not this is worth doing, but I thought it could be good to mention? |
ping @cynecx are you still interested in working on moving this forward? i'd like to get the IDE support issue fixed as soon as possible, so if you're busy, I'd be happy to take over getting this PR ready to merge. of course, we'd credit your work when merging even if I wrapped up this change. if you're still planning to work on it, that's totally fine --- i just thought i'd offer in the interest of fixing the issue as quickly as possible. thanks again for your work on this, in either case! |
@hawkw Sorry about the delay (I haven't had time to work on this until now)! Yes, I am still interested in moving this forward. I'll address the comments asap :) |
cd5c860
to
fef5384
Compare
If I understand correctly, cloning the |
Ah, in that case, I think this approach is fine! It might be nice to have a comment noting that this is cheap, but I don't think it's really a blocker in any case. |
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.
looks good to me, modulo one question about a comment
@hawkw Thanks for the feedback. I’ll address the comments when I am back home… :) |
@hawkw Btw, I've addressed your comments :) |
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.
Okay, this looks good to me! Thanks @cynecx for all your hard work on this!
@hawkw Also, Thank You for adding a proper commit message :D |
## Motivation Recent `rust-analyzer` versions enabled automatic expansion of proc macro attributes by default. This is a problem with `#[instrument]`, because it currently produces a `compile_error!` when parsing the code inside the `#[instrument]`ed function fails, and *discards* those tokens. This means that if the `#[instrument]` attribute is placed on a function whose implementation fails to parse, recent versions of `rust-analyzer` will no longer be able to display diagnostics for those errors. In some cases, this can also break autocompletion. ## Solution This branch changes `#[instrument]` to always expand to the tokens contained in the `#[instrument]`ed function body, regardless of whether or not they could be parsed successfully. Now, an error is only emitted when the `#[instrument]` attribute *itself* could not be parsed. Since the instrumented function is always expanded, any errors within that function can be displayed properly by `rust-analyzer`. Fixes #1633.
## Motivation Recent `rust-analyzer` versions enabled automatic expansion of proc macro attributes by default. This is a problem with `#[instrument]`, because it currently produces a `compile_error!` when parsing the code inside the `#[instrument]`ed function fails, and *discards* those tokens. This means that if the `#[instrument]` attribute is placed on a function whose implementation fails to parse, recent versions of `rust-analyzer` will no longer be able to display diagnostics for those errors. In some cases, this can also break autocompletion. ## Solution This branch changes `#[instrument]` to always expand to the tokens contained in the `#[instrument]`ed function body, regardless of whether or not they could be parsed successfully. Now, an error is only emitted when the `#[instrument]` attribute *itself* could not be parsed. Since the instrumented function is always expanded, any errors within that function can be displayed properly by `rust-analyzer`. Fixes #1633.
# 0.1.19 (February 3, 2022) This release introduces a new `#[instrument(ret)]` argument to emit an event with the return value of an instrumented function. ### Added - `#[instrument(ret)]` to record the return value of a function ([#1716]) - added `err(Debug)` argument to cause `#[instrument(err)]` to record errors with `Debug` rather than `Display ([#1631]) ### Fixed - incorrect code generation for functions returning async blocks ([#1866]) - incorrect diagnostics when using `rust-analyzer` ([#1634]) Thanks to @Swatinem, @hkmatsumoto, @cynecx, and @ciuncan for contributing to this release! [#1716]: #1716 [#1631]: #1631 [#1634]: #1634 [#1866]: #1866
# 0.1.19 (February 3, 2022) This release introduces a new `#[instrument(ret)]` argument to emit an event with the return value of an instrumented function. ### Added - `#[instrument(ret)]` to record the return value of a function ([#1716]) - added `err(Debug)` argument to cause `#[instrument(err)]` to record errors with `Debug` rather than `Display ([#1631]) ### Fixed - incorrect code generation for functions returning async blocks ([#1866]) - incorrect diagnostics when using `rust-analyzer` ([#1634]) Thanks to @Swatinem, @hkmatsumoto, @cynecx, and @ciuncan for contributing to this release! [#1716]: #1716 [#1631]: #1631 [#1634]: #1634 [#1866]: #1866
# 0.1.19 (February 3, 2022) This release introduces a new `#[instrument(ret)]` argument to emit an event with the return value of an instrumented function. ### Added - `#[instrument(ret)]` to record the return value of a function ([tokio-rs#1716]) - added `err(Debug)` argument to cause `#[instrument(err)]` to record errors with `Debug` rather than `Display ([tokio-rs#1631]) ### Fixed - incorrect code generation for functions returning async blocks ([tokio-rs#1866]) - incorrect diagnostics when using `rust-analyzer` ([tokio-rs#1634]) Thanks to @Swatinem, @hkmatsumoto, @cynecx, and @ciuncan for contributing to this release! [tokio-rs#1716]: tokio-rs#1716 [tokio-rs#1631]: tokio-rs#1631 [tokio-rs#1634]: tokio-rs#1634 [tokio-rs#1866]: tokio-rs#1866
Fixes #1633.
I intentially did not open a PR because the code isn't really polished and I wasn't sure if that is the right approach. I just needed something quickly to improve my rust-analyzer experience with a project. But here we go...
TODO: Check approach, polish/optimize code (eg. I wasn't sure if cloning a
TokenStream
is "zero/low-cost").