-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Unhelpful error message: E0283 ("type annotations needed") when proper solution is to remove where-constraint #73082
Copy link
Copy link
Closed
Description
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:
trait Deserialize<'a> {}
trait DeserializeOwned: for<'a> Deserialize<'a> {}
trait Mine : 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> for M {}
fn main()
{
} 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.