Skip to content

Invalid help message when traits in #[derive()] miss type annotation #75343

@yshui

Description

@yshui
#[derive(Serialize, Deserialize)]
struct Container<T: Serialize + Deserialize> {
	data: T
}

Which gives me this error message:

error[E0283]: type annotations needed
  --> src/main.rs:33:21
   |
33 | #[derive(Serialize, Deserialize)]
   |                     ^^^^^^^^^^^ cannot infer type for type parameter `T`
34 | struct Container<T: Serialize + Deserialize> {
   |                                 ----------- required by this bound in `Container`
   |
   = note: cannot satisfy `T: _::_serde::Deserialize<'static>`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider specifying the type argument in the function call
   |
33 | #[derive(Serialize, Deserialize::<T>)]

Which suggests invalid modification.

rustc --version --verbose:

rustc 1.47.0-nightly (09f4c9f50 2020-08-07)
binary: rustc
commit-hash: 09f4c9f5082f78b0adcee83d3ab4337e000cd28e
commit-date: 2020-08-07
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions