Skip to content

Commit 2b2434e

Browse files
committed
use_self - add test case of #4305
1 parent 96e8c0d commit 2b2434e

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

tests/ui/use_self.fixed

+49
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,52 @@ mod generics {
287287
}
288288
}
289289
}
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+
}

tests/ui/use_self.rs

+49
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,52 @@ mod generics {
287287
}
288288
}
289289
}
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+
}

tests/ui/use_self.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,17 @@ error: unnecessary structure name repetition
166166
LL | Foo { value }
167167
| ^^^ help: use the applicable keyword: `Self`
168168

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
170182

0 commit comments

Comments
 (0)