dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Self:: doesn't work in patterns #81

Closed dtolnay closed 4 years ago

dtolnay commented 4 years ago
use async_trait::async_trait;

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

pub enum Enum {
    Variant,
}

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