dtolnay / async-trait

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

Self:: needs to be handled in tuple and struct variant paths #87

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago
use async_trait::async_trait;

#[async_trait]
pub trait Trait {
    async fn f(&self);
}

pub enum Tuple {
    V(),
}

pub enum Struct {
    V {},
}

#[async_trait]
impl Trait for Tuple {
    async fn f(&self) {
        let Tuple::V() = self; // works
        let Self::V() = self; // does not work
    }
}

#[async_trait]
impl Trait for Struct {
    async fn f(&self) {
        let Struct::V {} = self; // works
        let Self::V {} = self; // does not work
    }
}
error[E0401]: can't use generic parameters from outer function
   --> tests/test.rs:609:17
    |
606 |     impl Trait for Tuple {
    |     ---- `Self` type implicitly declared here, by this `impl`
...
609 |             let Self::V() = self;
    |                 ^^^^^^^
    |                 |
    |                 use of generic parameter from outer function
    |                 use a type here instead

error[E0401]: can't use generic parameters from outer function
   --> tests/test.rs:617:17
    |
614 |     impl Trait for Struct {
    |     ---- `Self` type implicitly declared here, by this `impl`
...
617 |             let Self::V {} = self;
    |                 ^^^^^^^
    |                 |
    |                 use of generic parameter from outer function
    |                 use a type here instead