dtolnay / async-trait

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

Preserve span of Self keyword #102

Closed taiki-e closed 4 years ago

taiki-e commented 4 years ago

The following code:

use async_trait::async_trait;

pub struct Struct {}

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

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

The error message points to wrong span:

error[E0423]: expected value, found struct `Struct`
  --> src/lib.rs:11:16
   |
11 | impl Trait for Struct {
   |                ^^^^^^ did you mean `(Struct { /* fields */ })`?
   |

This PR fixes span of Self keyword to make the error message to point to the correct span:

error[E0423]: expected value, found struct `Struct`
  --> $DIR/self-span.rs:14:23
   |
3  | pub struct Struct {}
   | -------------------- `Struct` defined here
...
14 |         let _: Self = Self;
   |                       ^^^^ did you mean `Struct { /* fields */ }`?
   |