-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
self parameter gets expanded as module self in macro #46
Comments
Thanks! Looks like some kind of span issue because the code we are emitting does work by itself. I will take a look in the next couple days (but I would gladly accept a PR to fix this if you get to it first). Here is the code we currently expand this to: pub trait AsyncCommands: Sized {
fn f<'life0, 'async_trait, K: Send>(
&'life0 mut self,
x: K,
) -> ::core::pin::Pin<
Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>,
>
where
K: 'async_trait,
'life0: 'async_trait,
Self: ::core::marker::Send + 'async_trait,
{
#[allow(clippy::used_underscore_binding)]
async fn __f<K: Send, AsyncTrait: ?Sized + AsyncCommands + ::core::marker::Send>(
_self: &mut AsyncTrait,
x: K,
) {
_self.f(x).await
}
Box::pin(__f::<K, Self>(self, x))
}
} |
This is being caused by rust-lang/rust#43081 which means unfortunately there is nothing we can do about it in async-trait. The compiler loses all span information on the macro input before it's even passed in to async-trait, which makes TokenStream [
Ident {
ident: "pub",
span: #0 bytes(0..0),
},
Ident {
ident: "trait",
span: #0 bytes(0..0),
},
Ident {
ident: "AsyncCommands",
span: #0 bytes(0..0),
},
Punct {
ch: ':',
spacing: Alone,
span: #0 bytes(0..0),
},
Ident {
ident: "Sized",
span: #0 bytes(0..0),
},
Group { As a workaround, for some reason the compiler doesn't mess up if you use $:tt in the macro variables instead. ($tyargs:tt : $ty:tt) => { |
@dtolnay is this a compiler bug which will be fixed eventually, or intended compiler behavior? |
Minimal reproduction
The text was updated successfully, but these errors were encountered: