-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify existing bounds if they exist
- Loading branch information
1 parent
044a28a
commit af5a37e
Showing
13 changed files
with
186 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pub trait TryAdd<Rhs = Self> { | ||
type Error; | ||
type Output; | ||
|
||
fn try_add(self, rhs: Rhs) -> Result<Self::Output, Self::Error>; | ||
} | ||
|
||
impl<T: TryAdd> TryAdd for Option<T> { | ||
type Error = <T as TryAdd>::Error; | ||
type Output = Option<<T as TryAdd>::Output>; | ||
|
||
fn try_add(self, rhs: Self) -> Result<Self::Output, Self::Error> { | ||
Ok(self) //~ ERROR mismatched types | ||
} | ||
} | ||
|
||
struct Other<A>(A); | ||
|
||
struct X; | ||
|
||
impl<T: TryAdd<Error = X>> TryAdd for Other<T> { | ||
type Error = <T as TryAdd>::Error; | ||
type Output = Other<<T as TryAdd>::Output>; | ||
|
||
fn try_add(self, rhs: Self) -> Result<Self::Output, Self::Error> { | ||
Ok(self) //~ ERROR mismatched types | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/restrict-existing-type-bounds.rs:13:12 | ||
| | ||
LL | impl<T: TryAdd> TryAdd for Option<T> { | ||
| - this type parameter | ||
... | ||
LL | Ok(self) | ||
| -- ^^^^ expected `Option<<T as TryAdd>::Output>`, found `Option<T>` | ||
| | | ||
| arguments to this enum variant are incorrect | ||
| | ||
= note: expected enum `Option<<T as TryAdd>::Output>` | ||
found enum `Option<T>` | ||
help: the type constructed contains `Option<T>` due to the type of the argument passed | ||
--> $DIR/restrict-existing-type-bounds.rs:13:9 | ||
| | ||
LL | Ok(self) | ||
| ^^^----^ | ||
| | | ||
| this argument influences the type of `Ok` | ||
note: tuple variant defined here | ||
--> $SRC_DIR/core/src/result.rs:LL:COL | ||
help: consider further restricting this bound | ||
| | ||
LL | impl<T: TryAdd<Output = T>> TryAdd for Option<T> { | ||
| ++++++++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/restrict-existing-type-bounds.rs:26:12 | ||
| | ||
LL | impl<T: TryAdd<Error = X>> TryAdd for Other<T> { | ||
| - this type parameter | ||
... | ||
LL | Ok(self) | ||
| -- ^^^^ expected `Other<<T as TryAdd>::Output>`, found `Other<T>` | ||
| | | ||
| arguments to this enum variant are incorrect | ||
| | ||
= note: expected struct `Other<<T as TryAdd>::Output>` | ||
found struct `Other<T>` | ||
help: the type constructed contains `Other<T>` due to the type of the argument passed | ||
--> $DIR/restrict-existing-type-bounds.rs:26:9 | ||
| | ||
LL | Ok(self) | ||
| ^^^----^ | ||
| | | ||
| this argument influences the type of `Ok` | ||
note: tuple variant defined here | ||
--> $SRC_DIR/core/src/result.rs:LL:COL | ||
help: consider further restricting this bound | ||
| | ||
LL | impl<T: TryAdd<Error = X, Output = T>> TryAdd for Other<T> { | ||
| ++++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |