rust-lang / rust-lang/rust

`#[derive(Deserialize)]` makes rustc sugget suggests bizarre and non-working `use crate::_::_serde::de::Error;` instead of `use serde::de::Error;`

Open
#153,459 2 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

A-diagnostics D-incorrect T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
use serde::{Deserialize, de};
use std::collections::BTreeMap;
use std::str::FromStr;

#[derive(Deserialize, Debug, Clone)]
struct Struct {
    a: (),
}

fn main() {}

pub struct StringValuedIntMapVisitor;
impl<'de> de::Visitor<'de> for StringValuedIntMapVisitor {
    type Value = BTreeMap<u64, ()>;

    fn expecting(&self, _: &mut std::fmt::Formatter) -> std::fmt::Result {
        unimplemented!()
    }

    fn visit_map<M: de::MapAccess<'de>>(self, mut access: M) -> Result<Self::Value, M::Error> {
        // use serde::de::Error;
        while let Some((key_s, value)) = access.next_entry()? {
            let _ = u64::from_str(key_s).map_err(|e| M::Error::custom(e))?;
        }
        unimplemented!()
    }
}
Current output
error[E0599]: no function or associated item named `custom` found for associated type `<M as MapAccess<'de>>::Error` in the current scope
  --> src/main.rs:23:64
   |
23 |             let _ = u64::from_str(key_s).map_err(|e| M::Error::custom(e))?;
   |                                                                ^^^^^^ function or associated item not found in `<M as MapAccess<'de>>::Error`
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `Error` which provides `custom` is implemented but not in scope; perhaps you want to import it
   |
 1 + use crate::_::_serde::de::Error;
   |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `report` (bin "report") due to 1 previous error
Desired output
error[E0599]: no function or associated item named `custom` found for associated type `<M as MapAccess<'de>>::Error` in the current scope
  --> src/main.rs:23:64
   |
23 |             let _ = u64::from_str(key_s).map_err(|e| M::Error::custom(e))?;
   |                                                                ^^^^^^ function or associated item not found in `<M as MapAccess<'de>>::Error`
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `Error` which provides `custom` is implemented but not in scope; perhaps you want to import it
   |
 1 + use serde::de::Error;
   |

For more information about this error, try `rustc --explain E0599`.
Rationale and extra context

This is already the output if you comment out the #[derive( line.

Other cases
// #[derive(Deserialize, Debug, Clone)]
Rust Version
cargo 1.96.0-nightly (f298b8c82 2026-02-24)
release: 1.96.0-nightly
commit-hash: f298b8c82da0cba538516b45b04a480fc501d4c0
commit-date: 2026-02-24
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Debian 12.0.0 (bookworm) [64-bit]
Anything else?
[dependencies]
serde = {version = "1.0.228", features = ["derive"]}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.