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

Preserve the span of self argument #105

Merged
merged 1 commit into from Jun 8, 2020
Merged

Conversation

taiki-e
Copy link
Contributor

@taiki-e taiki-e commented Jun 8, 2020

Fixes #46
Fixes #104

@taiki-e taiki-e changed the title Propagate the span of self argument to inner function call Propagate the span of self argument Jun 8, 2020
@taiki-e taiki-e changed the title Propagate the span of self argument Propagate the span of self argument to inner function call Jun 8, 2020
@taiki-e
Copy link
Contributor Author

taiki-e commented Jun 8, 2020

Hm, this title is hard to understand. Maybe "Preserve the span of self argument" properly expresses what this PR does...

@taiki-e taiki-e changed the title Propagate the span of self argument to inner function call Preserve the span of self argument Jun 8, 2020
@taiki-e
Copy link
Contributor Author

taiki-e commented Jun 8, 2020

The reason this issue doesn't occur with arguments other than self is that the span between defining and using the self argument is different.

For example, if we replace the span of other arguments with call-site, we can reproduce the same error with other arguments.

async-trait/src/expand.rs

Lines 263 to 265 in 5220bbd

if let Pat::Ident(PatIdent { ident, .. }) = &*arg.pat {
quote!(#ident)
} else {

         if let Pat::Ident(PatIdent { ident, .. }) = &*arg.pat {
+            let ident = Ident::new(&ident.to_string(), Span::call_site());
             quote!(#ident)
         } else {
error[E0425]: cannot find value `x` in this scope
   --> tests/test.rs:576:13
    |
576 |             #[async_trait]
    |             ^^^^^^^^^^^^^^ not found in this scope
...
585 |     implement_commands! { K: Send }
    |     ------------------------------- in this macro invocation
    |

(in any case, the issue itself is definitely a compiler bug.)

bors bot added a commit to taiki-e/pin-project that referenced this pull request Jun 8, 2020
250: Preserve the span of self argument r=taiki-e a=taiki-e

Refs: dtolnay/async-trait#105

`#[pinned_drop]` attribute also has same issue.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
bors bot added a commit to taiki-e/pin-project that referenced this pull request Jun 8, 2020
250: Preserve the span of self argument r=taiki-e a=taiki-e

Refs: dtolnay/async-trait#105

`#[pinned_drop]` attribute also has same issue.

Co-authored-by: Taiki Endo <te316e89@gmail.com>
Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks! I didn't know this could be something we can fix.

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.

Problem with declarative macros self parameter gets expanded as module self in macro
2 participants