Repository navigation
#[derive(Deserialize)] makes rustc sugget suggests bizarre and non-working use crate::_::_serde::de::Error; instead of use serde::de::Error; #153459
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-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
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"]}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.T-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
Tabrezz3 commentedon Mar 6, 2026
@rustbot claim
raushan728 commentedon Jul 8, 2026
@rustbot claim
Rollup merge of rust-lang#158997 - raushan728:issues/153459, r=petroc…
Rollup merge of rust-lang#158997 - raushan728:issues/153459, r=petroc…
Auto merge of #158997 - raushan728:issues/153459, r=petrochenkov
Auto merge of #158997 - raushan728:issues/153459, r=petrochenkov
Rollup merge of rust-lang#158997 - raushan728:issues/153459, r=petroc…
Unrolled build for #158997 in rollup 163472
Rollup merge of #158997 - raushan728:issues/153459, r=petrochenkov