File tree 3 files changed +111
-1
lines changed
3 files changed +111
-1
lines changed Original file line number Diff line number Diff line change @@ -287,3 +287,52 @@ mod generics {
287
287
}
288
288
}
289
289
}
290
+
291
+ mod issue4305 {
292
+ pub struct Error<From, To> {
293
+ _from: From,
294
+ _too: To,
295
+ }
296
+
297
+ pub trait From<T> {
298
+ type From;
299
+ type To;
300
+
301
+ fn from(value: T) -> Self;
302
+ }
303
+
304
+ pub trait TryFrom<T>
305
+ where
306
+ Self: Sized,
307
+ {
308
+ type From;
309
+ type To;
310
+
311
+ fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
312
+ }
313
+
314
+ impl<F, T> TryFrom<F> for T
315
+ where
316
+ T: From<F>,
317
+ {
318
+ type From = Self;
319
+ type To = Self;
320
+
321
+ fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
322
+ Ok(From::from(value))
323
+ }
324
+ }
325
+
326
+ impl From<bool> for i64 {
327
+ type From = bool;
328
+ type To = Self;
329
+
330
+ fn from(value: bool) -> Self {
331
+ if value {
332
+ 100
333
+ } else {
334
+ 0
335
+ }
336
+ }
337
+ }
338
+ }
Original file line number Diff line number Diff line change @@ -287,3 +287,52 @@ mod generics {
287
287
}
288
288
}
289
289
}
290
+
291
+ mod issue4305 {
292
+ pub struct Error < From , To > {
293
+ _from : From ,
294
+ _too : To ,
295
+ }
296
+
297
+ pub trait From < T > {
298
+ type From ;
299
+ type To ;
300
+
301
+ fn from ( value : T ) -> Self ;
302
+ }
303
+
304
+ pub trait TryFrom < T >
305
+ where
306
+ Self : Sized ,
307
+ {
308
+ type From ;
309
+ type To ;
310
+
311
+ fn try_from ( value : T ) -> Result < Self , Error < Self :: From , Self :: To > > ;
312
+ }
313
+
314
+ impl < F , T > TryFrom < F > for T
315
+ where
316
+ T : From < F > ,
317
+ {
318
+ type From = T :: From ;
319
+ type To = T :: To ;
320
+
321
+ fn try_from ( value : F ) -> Result < Self , Error < Self :: From , Self :: To > > {
322
+ Ok ( From :: from ( value) )
323
+ }
324
+ }
325
+
326
+ impl From < bool > for i64 {
327
+ type From = bool ;
328
+ type To = Self ;
329
+
330
+ fn from ( value : bool ) -> Self {
331
+ if value {
332
+ 100
333
+ } else {
334
+ 0
335
+ }
336
+ }
337
+ }
338
+ }
Original file line number Diff line number Diff line change @@ -166,5 +166,17 @@ error: unnecessary structure name repetition
166
166
LL | Foo { value }
167
167
| ^^^ help: use the applicable keyword: `Self`
168
168
169
- error: aborting due to 26 previous errors
169
+ error: unnecessary structure name repetition
170
+ --> $DIR/use_self.rs:318:21
171
+ |
172
+ LL | type From = T::From;
173
+ | ^^^^^^^ help: use the applicable keyword: `Self`
174
+
175
+ error: unnecessary structure name repetition
176
+ --> $DIR/use_self.rs:319:19
177
+ |
178
+ LL | type To = T::To;
179
+ | ^^^^^ help: use the applicable keyword: `Self`
180
+
181
+ error: aborting due to 28 previous errors
170
182
You can’t perform that action at this time.
0 commit comments