Skip to content

Confusing diagnostics on #[derive(X)] when X is imported only as trait #88206

Closed
@m-ou-se

Description

@m-ou-se

Reported by @Hoverbear here: https://twitter.com/a_hoverbear/status/1428763621572501507

use serde::{Deserialize, Serialize};

#[derive(Serialize)]
struct A;

Output:

error: cannot find derive macro `Serialize` in this scope
 --> src/main.rs:3:10
  |
3 | #[derive(Serialize)]
  |          ^^^^^^^^^

warning: unused import: `serde::Serialize`
 --> src/main.rs:1:5
  |
1 | use serde::Serialize;
  |     ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

The diagnostics shows that Serialize is not found, and then complains that Serialize was imported and unused. Confusing.

(Only the trait Serialize is imported, not the Serialize derive macro, as the derive feature wasn't enabled on serde.)

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions