dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.84k stars 85 forks source link

Preserve the span of self argument #105

Closed taiki-e closed 4 years ago

taiki-e commented 4 years ago

Fixes #46 Fixes #104

taiki-e commented 4 years ago

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

taiki-e commented 4 years ago

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.

https://github.com/dtolnay/async-trait/blob/5220bbd2bdf30fa43c78d08a8e9a9f311a239cf8/src/expand.rs#L263-L265

         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.)