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: remove direct dependency on proc-macro2 #296

Merged
merged 1 commit into from Aug 20, 2019
Merged

attributes: remove direct dependency on proc-macro2 #296

merged 1 commit into from Aug 20, 2019

Conversation

jarrodldavis
Copy link
Contributor

Motivation

As discussed in #292:

A follow-up to remove an explicit dependency on proc-macro2 would be great, though, as it would make it easier to avoid pulling duplicate versions of that crate.

Solution

Remove proc-macro2 as a direct dependency and replace usages of types from it accordingly.

- 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
Copy link
Member

@hawkw hawkw left a 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!(
Copy link
Member

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.

Copy link
Contributor Author

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()=> …)

Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@hawkw hawkw left a 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!(
Copy link
Member

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!

@hawkw hawkw merged commit b6ad438 into tokio-rs:master Aug 20, 2019
hawkw added a commit that referenced this pull request Aug 20, 2019
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Aug 20, 2019
### Changed:

- Updated `syn` and `quote` dependencies to 1.0 (#292)
- Removed direct dependency on `proc-macro2` to avoid potential version
  conflicts (#296)

### Fixed:

- Outdated idioms in examples (#271, #273)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@jarrodldavis jarrodldavis deleted the more-macro-updates branch August 20, 2019 19:57
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

2 participants