Skip to content

Commit

Permalink
use_self - add test case of rust-lang#4305
Browse files Browse the repository at this point in the history
  • Loading branch information
tnielens committed Apr 26, 2020
1 parent c53e6db commit 5fbdf31
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
49 changes: 49 additions & 0 deletions tests/ui/use_self.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,52 @@ mod generics {
}
}
}

mod issue4305 {
pub struct Error<From, To> {
_from: From,
_too: To,
}

pub trait From<T> {
type From;
type To;

fn from(value: T) -> Self;
}

pub trait TryFrom<T>
where
Self: Sized,
{
type From;
type To;

fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
}

impl<F, T> TryFrom<F> for T
where
T: From<F>,
{
type From = Self;
type To = Self;

fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
Ok(From::from(value))
}
}

impl From<bool> for i64 {
type From = bool;
type To = Self;

fn from(value: bool) -> Self {
if value {
100
} else {
0
}
}
}
}
49 changes: 49 additions & 0 deletions tests/ui/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,52 @@ mod generics {
}
}
}

mod issue4305 {
pub struct Error<From, To> {
_from: From,
_too: To,
}

pub trait From<T> {
type From;
type To;

fn from(value: T) -> Self;
}

pub trait TryFrom<T>
where
Self: Sized,
{
type From;
type To;

fn try_from(value: T) -> Result<Self, Error<Self::From, Self::To>>;
}

impl<F, T> TryFrom<F> for T
where
T: From<F>,
{
type From = T::From;
type To = T::To;

fn try_from(value: F) -> Result<Self, Error<Self::From, Self::To>> {
Ok(From::from(value))
}
}

impl From<bool> for i64 {
type From = bool;
type To = Self;

fn from(value: bool) -> Self {
if value {
100
} else {
0
}
}
}
}
14 changes: 13 additions & 1 deletion tests/ui/use_self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,17 @@ error: unnecessary structure name repetition
LL | Foo { value }
| ^^^ help: use the applicable keyword: `Self`

error: aborting due to 26 previous errors
error: unnecessary structure name repetition
--> $DIR/use_self.rs:318:21
|
LL | type From = T::From;
| ^^^^^^^ help: use the applicable keyword: `Self`

error: unnecessary structure name repetition
--> $DIR/use_self.rs:319:19
|
LL | type To = T::To;
| ^^^^^ help: use the applicable keyword: `Self`

error: aborting due to 28 previous errors

0 comments on commit 5fbdf31

Please sign in to comment.