-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust incorrectly concludes that trait is not implemented #82252
Comments
Two year later I've came across this issue again, and I've got some more practical example where the type system breaks. I was trying to implement impl<'de, T> serde_with::DeserializeAs<'de, T> for MyType
where
T: TryFrom<&[u8]>,
<T as TryFrom<&[u8]>>::Error: Display
{ /* ... */ } However, here Rust forces me to use impl<'de, T> serde_with::DeserializeAs<'de, T> for MyType
where
for<'a> T: TryFrom<&'a [u8]>,
for<'a> <T as TryFrom<&'a [u8]>>::Error: std::fmt::Display,
{ /* ... */ } The type system is capable of figuring out that fn it_implements_trait<'de, M, T>()
where
M: serde_with::DeserializeAs<'de, T>,
{}
it_implements_trait::<MyType, [u8; 32]>(); // this compiles
it_implements_trait::<Option<MyType>, Option<[u8; 32]>>(); // and that compiles but it breaks when it's needed the most: inside struct Foo([u8; 32]);
impl<'de> serde::Deserialize<'de> for Foo {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let inner: [u8; 32] = serde_with::As::<MyType>::deserialize(deserializer)?;
Ok(Self(inner))
}
} ...that causes a compilation error:
which is not true because |
The first example compiles on latest Rust, so I suppose it is indeed fixed! |
Suppose I have a function:
Here, for some reason, Rust refuses to infer that
<T as TryFrom<&'a U64>>::Error
implements Debug. Can be checked by adding more code:If we replace main function with:
then it will be compiled, so Rust is able to infer that TooLargeErr implements Debug, but it doesn't do the same in generic bounds.
Here's a link on playground
Meta
Reproduces at Rust 1.50.0 stable, beta, nightly
The text was updated successfully, but these errors were encountered: