dtolnay / async-trait

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

Propagate the span of Self keyword to QSelf #103

Closed taiki-e closed 4 years ago

taiki-e commented 4 years ago

A similar case to #102.

The following code:

pub enum E {
    V {}
}

#[async_trait]
impl Trait for E {
    async fn method(self) {
        let _: () = self;
        let _: Self = Self::V;
    }
}

The error message points to call-site span:

error[E0533]: expected unit struct, unit variant or constant, found struct variant `#[async_trait]`
  --> $DIR/self-span.rs:22:1
   |
22 | #[async_trait]
   | ^^^^^^^^^^^^^^
   |

This PR fixes span of < and > tokens of QSelf to make the error message to point to the correct span:

error[E0533]: expected unit struct, unit variant or constant, found struct variant `Self::V`
  --> $DIR/self-span.rs:26:23
   |
26 |         let _: Self = Self::V;
   |                       ^^^^^^^

(this originally caught in https://github.com/taiki-e/pin-project/pull/249. also https://github.com/serde-rs/serde/pull/1830 is already updated to include this)