|
| 1 | +#![feature(fn_delegation)] |
| 2 | + |
| 3 | +mod success { |
| 4 | + trait Trait { |
| 5 | + fn method(&self) -> Self; |
| 6 | + fn r#static() -> Self; |
| 7 | + fn raw_S(&self) -> S { S } |
| 8 | + } |
| 9 | + |
| 10 | + struct S; |
| 11 | + impl Trait for S { |
| 12 | + fn method(&self) -> S { S } |
| 13 | + fn r#static() -> S { S } |
| 14 | + } |
| 15 | + |
| 16 | + struct W(S); |
| 17 | + impl Trait for W { |
| 18 | + reuse Trait::method { self.0 } |
| 19 | + reuse Trait::r#static; |
| 20 | + reuse Trait::raw_S { self.0 } |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +mod success_generics { |
| 25 | + trait Trait<'a, T, const N: usize> { |
| 26 | + fn method(&self) -> Self; |
| 27 | + fn r#static() -> Self; |
| 28 | + fn raw_S(&self) -> S<'static, ()> { S::<'static, ()>(std::marker::PhantomData) } |
| 29 | + } |
| 30 | + |
| 31 | + struct S<'a, T>(std::marker::PhantomData<&'a T>); |
| 32 | + impl<'a, T, const N: usize> Trait<'a, T, N> for S<'a, T> { |
| 33 | + fn method(&self) -> S<'a, T> { |
| 34 | + S(std::marker::PhantomData) |
| 35 | + } |
| 36 | + |
| 37 | + fn r#static() -> S<'a, T> { S(std::marker::PhantomData) } |
| 38 | + } |
| 39 | + |
| 40 | + struct W<'a, T>(S<'a, T>); |
| 41 | + impl<'a, T, const N: usize> Trait<'a, T, N> for W<'a, T> { |
| 42 | + reuse Trait::<'a, T, N>::method { self.0 } |
| 43 | + reuse Trait::<'a, T, N>::r#static; |
| 44 | + reuse Trait::<'a, T, N>::raw_S { self.0 } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +mod more_than_one_field { |
| 49 | + trait Trait { |
| 50 | + fn method(&self) -> Self; |
| 51 | + fn r#static() -> Self; |
| 52 | + fn raw_S(&self) -> S { S } |
| 53 | + } |
| 54 | + |
| 55 | + struct S; |
| 56 | + impl Trait for S { |
| 57 | + fn method(&self) -> S { S } |
| 58 | + fn r#static() -> S { S } |
| 59 | + } |
| 60 | + |
| 61 | + struct W(S, S, S); |
| 62 | + impl Trait for W { |
| 63 | + reuse Trait::method { self.0 } |
| 64 | + //~^ ERROR: mismatched types |
| 65 | + |
| 66 | + reuse Trait::r#static { self.0 } |
| 67 | + //~^ ERROR: delegation's target expression is specified for function with no params |
| 68 | + //~| ERROR: method `static` has an incompatible type for trait |
| 69 | + //~| ERROR: this function takes 0 arguments but 1 argument was supplied |
| 70 | + //~| ERROR: the trait bound `(): more_than_one_field::Trait` is not satisfied |
| 71 | + |
| 72 | + reuse Trait::raw_S { self.0 } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +mod non_trait_path_reuse { |
| 77 | + trait Trait { |
| 78 | + fn method(&self) -> Self; |
| 79 | + fn r#static() -> Self; |
| 80 | + fn raw_S(&self) -> S { S } |
| 81 | + } |
| 82 | + |
| 83 | + mod to_reuse { |
| 84 | + pub fn method(_: impl super::Trait) -> impl super::Trait { |
| 85 | + super::S |
| 86 | + } |
| 87 | + |
| 88 | + pub fn r#static() -> impl super::Trait { |
| 89 | + super::S |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + pub struct S; |
| 94 | + impl Trait for S { |
| 95 | + fn method(&self) -> S { S } |
| 96 | + fn r#static() -> S { S } |
| 97 | + } |
| 98 | + |
| 99 | + struct W(S); |
| 100 | + impl Trait for W { |
| 101 | + reuse to_reuse::method { self.0 } |
| 102 | + //~^ ERROR: mismatched types |
| 103 | + reuse to_reuse::r#static; |
| 104 | + //~^ ERROR: mismatched types |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +mod non_Self_return_type { |
| 109 | + trait Trait { |
| 110 | + fn method(&self) -> (); |
| 111 | + fn r#static() -> (); |
| 112 | + fn raw_S(&self) -> S { S } |
| 113 | + } |
| 114 | + |
| 115 | + struct S; |
| 116 | + impl Trait for S { |
| 117 | + fn method(&self) -> () { () } |
| 118 | + fn r#static() -> () { () } |
| 119 | + fn raw_S(&self) -> S { S } |
| 120 | + } |
| 121 | + |
| 122 | + struct W(()); |
| 123 | + impl Trait for W { |
| 124 | + reuse Trait::method { self.0 } |
| 125 | + //~^ ERROR: mismatched types |
| 126 | + |
| 127 | + reuse Trait::r#static; |
| 128 | + //~^ ERROR: type annotations needed |
| 129 | + |
| 130 | + reuse Trait::raw_S { self.0 } |
| 131 | + //~^ ERROR: mismatched types |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +mod wrong_return_type { |
| 136 | + trait Trait { |
| 137 | + fn method(&self) -> Self; |
| 138 | + fn r#static() -> Self; |
| 139 | + fn raw_S(&self) -> S { S } |
| 140 | + } |
| 141 | + |
| 142 | + struct F; |
| 143 | + impl Trait for F { |
| 144 | + fn method(&self) -> F { F } |
| 145 | + fn r#static() -> F { F } |
| 146 | + } |
| 147 | + |
| 148 | + struct S; |
| 149 | + impl Trait for S { |
| 150 | + fn method(&self) -> S { S } |
| 151 | + fn r#static() -> S { S } |
| 152 | + } |
| 153 | + |
| 154 | + struct W(S); |
| 155 | + impl Trait for W { |
| 156 | + reuse <F as Trait>::method { self.0 } |
| 157 | + //~^ ERROR: mismatched types |
| 158 | + //~| ERROR: mismatched types |
| 159 | + |
| 160 | + reuse <F as Trait>::r#static; |
| 161 | + //~^ ERROR: mismatched types |
| 162 | + |
| 163 | + reuse <F as Trait>::raw_S { self.0 } |
| 164 | + //~^ ERROR: mismatched types |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | +mod wrong_target_expression { |
| 169 | + trait Trait { |
| 170 | + fn method(&self) -> Self; |
| 171 | + fn r#static() -> Self; |
| 172 | + fn raw_S(&self) -> S { S } |
| 173 | + } |
| 174 | + |
| 175 | + struct S; |
| 176 | + impl Trait for S { |
| 177 | + fn method(&self) -> S { S } |
| 178 | + fn r#static() -> S { S } |
| 179 | + } |
| 180 | + |
| 181 | + struct F; |
| 182 | + impl Trait for F { |
| 183 | + fn method(&self) -> F { F } |
| 184 | + fn r#static() -> F { F } |
| 185 | + } |
| 186 | + |
| 187 | + struct W(S); |
| 188 | + impl Trait for W { |
| 189 | + reuse Trait::method { F } |
| 190 | + //~^ ERROR: mismatched types |
| 191 | + |
| 192 | + reuse Trait::r#static; |
| 193 | + reuse Trait::raw_S { F } |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +fn main() {} |
0 commit comments