dtolnay / async-trait

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

Regression in associated type parsing in `0.1.67` #245

Closed daprilik closed 1 year ago

daprilik commented 1 year ago

Seems something slipped through the cracks during the port to syn 2?

I've got it down to a minimal repro that would compile fine on 0.1.66 and earlier, but doesn't anymore:

#[async_trait]
pub trait Bar {
    type Assoc<'a>: Send
    where
        Self: 'a;
}

#[async_trait]
impl<T: Bar> Bar for Foo<'_, T> {
    type Assoc<'a>
    where
        Self: 'a,
    = T::Assoc<'a>;
}

It's throwing a

error: expected `;`
  --> src/main.rs:17:5
   |
17 |     = T::Assoc<'a>;
   |     ^

Note that the following impl does compile:

#[async_trait]
impl<T: Bar> Bar for Foo<'_, T> {
    type Assoc<'a> = T::Assoc<'a> where Self: 'a,;
}

I'll be switching to the latter as a workaround, but it seems spooky for code to stop compiling.

dtolnay commented 1 year ago

There has never been a stable Rust release in which where-clause before type in an impl block was accepted -- it went from unstable in 1.64.0:

error[E0658]: generic associated types are unstable
  --> src/main.rs:10:5
   |
10 | /     type Assoc<'a>
11 | |     where
12 | |         Self: 'a,
13 | |     = T::Assoc<'a>;
   | |___________________^
   |
   = note: see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information

to "not allowed" in 1.65.0 and all subsequent releases:

warning: where clause not allowed here
  --> src/main.rs:11:5
   |
11 | /     where
12 | |         Self: 'a,
   | |_________________^
   |
   = note: `#[warn(deprecated_where_clause_location)]` on by default
   = note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
help: move it to the end of the type declaration
   |
11 ~     
12 ~     = T::Assoc<'a> where Self: 'a;
   |

Maybe something about macro expansion concealed this? In any case I think it's fine not to parse this code.