dtolnay / typetag

Serde serializable and deserializable trait objects
Apache License 2.0
1.19k stars 38 forks source link

Reject traits with associated types/consts #13

Closed jiangliu closed 1 year ago

jiangliu commented 5 years ago

A trait with associated types fails to compile. Suggest to check for those conditions in impl/src/tagged_trait.rs::expand().

#[typetag::serde(tag = "type")]
trait WebEvent {
    type A;
    fn inspect(&self);
}

/typetag.git $ cargo run --example web_event
   Compiling typetag v0.1.3 (/ws/src/rust/typetag.git)
error[E0191]: the value of the associated type `A` (from the trait `WebEvent`) must be specified
 --> examples/web_event.rs:5:1
  |
5 | #[typetag::serde(tag = "type")]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `A` must be specified
6 | trait WebEvent {
7 |     type A;
  |     ------- `A` defined here

error: aborting due to previous error