Closed
Description
I'm trying to get the following to compile.
pub trait MyTryFrom<T> {
type Error;
}
pub trait Foo {
type FooType;
fn foo<E>(x: Self::FooType) -> E
where
E: MyTryFrom<Self::FooType>,
E::Error: Sized;
}
struct MyFoo;
impl Foo for MyFoo {
type FooType = MyFooType;
fn foo<E>(x: Self::FooType) -> E
where
E: MyTryFrom<Self::FooType>,
E::Error: Sized,
{
todo!()
}
}
struct MyFooType;
This is a minimal example that illustrates the issue. The compiler gives me the following error, asking me to further restrict E
with the exact same bound.
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `E: MyTryFrom<MyFooType>` is not satisfied
--> src/lib.rs:19:5
|
19 | / fn foo<E>(x: Self::FooType) -> E
20 | | where
21 | | E: MyTryFrom<Self::FooType>,
22 | | E::Error: Sized,
| |________________________^ the trait `MyTryFrom<MyFooType>` is not implemented for `E`
|
help: consider further restricting this bound
|
21 | E: MyTryFrom<Self::FooType> + MyTryFrom<MyFooType>,
| ++++++++++++++++++++++
error[E0277]: the trait bound `E: MyTryFrom<MyFooType>` is not satisfied
--> src/lib.rs:19:8
|
19 | fn foo<E>(x: Self::FooType) -> E
| ^^^ the trait `MyTryFrom<MyFooType>` is not implemented for `E`
|
help: consider further restricting this bound
|
21 | E: MyTryFrom<Self::FooType> + MyTryFrom<MyFooType>,
| ++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 2 previous errors
This snippet compiles just fine if I remove the E::Error: Sized
bound.
Meta
I've tried this on stable (1.72.1) and nightly (1.75.0-nightly)
rustc --version --verbose
:
rustc 1.72.1 (d5c2e9c34 2023-09-13)
binary: rustc
commit-hash: d5c2e9c342b358556da91d61ed4133f6f50fc0c3
commit-date: 2023-09-13
host: x86_64-unknown-linux-gnu
release: 1.72.1
LLVM version: 16.0.5