Repository navigation
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
// https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=59c21350087b0a8594c3d41efc25b609
#[derive(Serialize)]
struct S;Current output
error: cannot find derive macro `Serialize` in this scope
--> src/main.rs:1:10
|
1 | #[derive(Serialize)]
| ^^^^^^^^^
|
note: `Serialize` is a trait, not a derive macro
--> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/markup5ever-0.12.1/serialize.rs:36:1
|
36 | pub trait Serialize {
| ^^^^^^^^^^^^^^^^^^^
note: `Serialize` is a trait, not a derive macro
--> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/markup5ever-0.11.0/serialize.rs:36:1
|
36 | pub trait Serialize {
| ^^^^^^^^^^^^^^^^^^^
note: `Serialize` is a trait, not a derive macro
--> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rkyv-0.8.18/src/traits.rs:262:1
|
262 | pub trait Serialize<S: Fallible + ?Sized>: Archive {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `Serialize` is a trait, not a derive macro
--> /playground/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/serde_core-1.0.229/src/ser/mod.rs:234:1
|
234 | pub trait Serialize {
| ^^^^^^^^^^^^^^^^^^^
= help: consider implementing `Serialize` for your type manually
help: consider importing one of these derive macros
|
1 + use noop_proc_macro::Serialize;
|
1 + use rkyv::Serialize;
|
1 + use rkyv_derive::Serialize;
|
1 + use serde::Serialize;
|
= and 1 other candidateDesired output
error: cannot find derive macro `Serialize` in this scope
--> src/main.rs:1:10
|
1 | #[derive(Serialize)]
| ^^^^^^^^^
|
help: consider importing one of these derive macros
|
1 + use noop_proc_macro::Serialize;
|
1 + use rkyv::Serialize;
|
1 + use rkyv_derive::Serialize;
|
1 + use serde::Serialize;
|
= and 1 other candidateRationale and extra context
When the derive macro with an appropriate name is suggested, we should likely not point at the traits with the same name, as the likelihood of the derives being what was desired is quite high, and the verbosity of the error currently is not ideal. We could also instead mention only the full paths for the existing traits in a single note, to reduce the verbosity.
Noticed while looking at #102601.
Other cases
Rust Version
1.98.1Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
estebank commentedon Sep 8, 2026
Another marginal improvement we could do is for the case where there is no derive merge the notes into a single one (it saves a few lines):
Rollup merge of rust-lang#162706 - chenyukang:yukang-fix-162260-hide-…
Unrolled build for #162706 in rollup 162742