1#![allow(clippy::used_underscore_binding)] 2 3use serde_derive::{Deserialize, Serialize}; 4 5#[test] 6fn test_self() { 7 pub trait Trait { 8 type Assoc; 9 } 10 11 #[derive(Deserialize, Serialize)] 12 pub struct Generics<T: Trait<Assoc = Self>> 13 where 14 Self: Trait<Assoc = Self>, 15 <Self as Trait>::Assoc: Sized, 16 { 17 _f: T, 18 } 19 20 impl<T: Trait<Assoc = Self>> Trait for Generics<T> { 21 type Assoc = Self; 22 } 23 24 #[derive(Deserialize, Serialize)] 25 pub struct Struct { 26 _f1: Box<Self>, 27 _f2: Box<<Self as Trait>::Assoc>, 28 _f4: [(); Self::ASSOC], 29 _f5: [(); Self::assoc()], 30 } 31 32 impl Struct { 33 const ASSOC: usize = 1; 34 const fn assoc() -> usize { 35 0 36 } 37 } 38 39 impl Trait for Struct { 40 type Assoc = Self; 41 } 42 43 #[derive(Deserialize, Serialize)] 44 struct Tuple( 45 Box<Self>, 46 Box<<Self as Trait>::Assoc>, 47 [(); Self::ASSOC], 48 [(); Self::assoc()], 49 ); 50 51 impl Tuple { 52 const ASSOC: usize = 1; 53 const fn assoc() -> usize { 54 0 55 } 56 } 57 58 impl Trait for Tuple { 59 type Assoc = Self; 60 } 61 62 #[derive(Deserialize, Serialize)] 63 enum Enum { 64 Struct { 65 _f1: Box<Self>, 66 _f2: Box<<Self as Trait>::Assoc>, 67 _f4: [(); Self::ASSOC], 68 _f5: [(); Self::assoc()], 69 }, 70 Tuple( 71 Box<Self>, 72 Box<<Self as Trait>::Assoc>, 73 [(); Self::ASSOC], 74 [(); Self::assoc()], 75 ), 76 } 77 78 impl Enum { 79 const ASSOC: usize = 1; 80 const fn assoc() -> usize { 81 0 82 } 83 } 84 85 impl Trait for Enum { 86 type Assoc = Self; 87 } 88} 89