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 direct dependency on proc-macro2 #296
Conversation
- remove `proc-macro2` as a direct dependency - replace usage of `TokenStream` from `proc-macro2` with `impl ToTokens` from `quote` - remove usage of `Span::call_site` as that is used by default for the `quote!` macro
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.
I think we should continue propagating the span from the original instrumented function in the quoted output so that we get nice compiler diagnostics if there are errors in the instrumented function. I mentioned in a comment how we could do that.
Beyond that, this looks great, and I'd be happy to merge once you make that change. Thanks!
@@ -187,7 +185,7 @@ pub fn instrument(args: TokenStream, item: TokenStream) -> TokenStream { | |||
let level = level(&args); | |||
let target = target(&args); | |||
|
|||
quote_spanned!(call_site=> | |||
quote!( |
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.
I think propagating the span of the original function is important, so that any errors are displayed correctly. Is there a way to do that using syn::spanned::Spanned
, so that we don't need to import the Span
type explicitly?
I believe that we can use the Spanned
impl for ItemFn
for this.
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.
I may be misunderstanding the documentation, but this seems to indicate that quote!(…)
does the same thing as quote_spanned!(Span::call_site()=> …)
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.
Oh, I think I missed that in the docs, that's great. Nevermind my previous comment!
@@ -204,7 +202,7 @@ pub fn instrument(args: TokenStream, item: TokenStream) -> TokenStream { | |||
.into() | |||
} | |||
|
|||
fn level(args: &AttributeArgs) -> proc_macro2::TokenStream { | |||
fn level(args: &AttributeArgs) -> impl ToTokens { |
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.
👍
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.
I'm going to go ahead and merge this so that it can get into the 0.1.2 release that's currently staged in #293. Thanks for the contribution!
@@ -187,7 +185,7 @@ pub fn instrument(args: TokenStream, item: TokenStream) -> TokenStream { | |||
let level = level(&args); | |||
let target = target(&args); | |||
|
|||
quote_spanned!(call_site=> | |||
quote!( |
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.
Oh, I think I missed that in the docs, that's great. Nevermind my previous comment!
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Motivation
As discussed in #292:
Solution
Remove
proc-macro2
as a direct dependency and replace usages of types from it accordingly.