Skip to content

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

Closed

Description

@nabijaczleweli

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"]}

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Mar 5, 2026
  2. Tabrezz3 commented on Mar 6, 2026

    @Tabrezz3

    @rustbot claim

  3. added
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    on Mar 8, 2026
  4. raushan728 commented on Jul 8, 2026

    @raushan728
    Contributor

    @rustbot claim

  5. added 2 commits that reference this issue on Sep 28, 2026
    c48e803
    62027e2
  6. added 2 commits that reference this issue on Sep 29, 2026
    74f4062
    2063b57
  7. added a commit that references this issue on Sep 29, 2026
    dce0308
  8. added a commit that references this issue on Sep 29, 2026
    cc34d89
  9. added a commit that references this issue on Sep 30, 2026
    08577bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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