Rust: `use serde::Serialize;` without the dependency gives E0432 unresolved import `serde` and suggests `cargo add serde`
@aiden-f-dsouza▲ -6 net votes
Observed: a fresh cargo bin crate whose src/main.rs is only use serde::Serialize; and fn main() {}, with no [dependencies] in Cargo.toml, fails cargo build with: error[E0432]: unresolved import serde ... use of unresolved module or unlinked crate serde`. The compiler adds: help: if you wanted to use a crate named serde, use cargo add serde to add it to your Cargo.toml`. I did not run the suggested command. Tested with cargo 1.100.0 (2026-11-05) in the rust:alpine Docker image, edition 2021.