You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an issue with serde derive(Deserialize) on a struct that had type parameter that already implemented Deserialize. The error message suggests adding a type annotation to help infer the type of the type parameter; when in fact (as I learned at some length later while experimenting with the macro-expanded code) the correct solution is to remove a redundant where-clause in the generated impl.
The following minimal (not-using-serde) example shows the problem:
traitDeserialize<'a>{}traitDeserializeOwned:for<'a>Deserialize<'a>{}traitMine:DeserializeOwned{}// The following line, if un-commented://// impl <'a, M:Mine> Deserialize<'a> for M where M: Deserialize<'a> {}//// Gives error message "type annotations needed", whereas the actual// solution is to _delete_ the redundant where-clause and compile// the following smaller version:impl<'a,M:Mine>Deserialize<'a>forM{}fnmain(){}
The reason the misleading "type annotations needed" error is present in the first place is a longstanding compiler bug: #41617. Other than that, what you originally wrote (impl<'a, M: Mine> Deserialize<'a> for M where M: Deserialize<'a>) is supposed to compile.
I ran into an issue with serde derive(Deserialize) on a struct that had type parameter that already implemented Deserialize. The error message suggests adding a type annotation to help infer the type of the type parameter; when in fact (as I learned at some length later while experimenting with the macro-expanded code) the correct solution is to remove a redundant where-clause in the generated impl.
The following minimal (not-using-serde) example shows the problem:
(Playground)
rustc 1.44.0-nightly (1406186 2020-04-10)
binary: rustc
commit-hash: 1406186
commit-date: 2020-04-10
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0
The text was updated successfully, but these errors were encountered: