Consider the following code as lib.rs:
pub trait Foo {
type AssocType;
const THE_CONST: Self::AssocType;
}
pub struct Bar;
impl Foo for Bar {
type AssocType = u32;
const THE_CONST: Self::AssocType = 1;
}
Running cargo doc and opening the generated html, one sees
Note
const THE_CONST: Self::AssocType = {transmute(0x00000001): <Bar as Foo>::AssocType}
Instead of the more reasonably expected
const THE_CONST: Self::AssocType = 1u32
or, barring that, just nothing instead of the confusing transmute string.
Meta
rustc --version --verbose:
rustc 1.91.0 (f8297e351 2025-10-28)
binary: rustc
commit-hash: f8297e351a40c1439a467bbbb6879088047f50b3
commit-date: 2025-10-28
host: x86_64-unknown-linux-gnu
release: 1.91.0
LLVM version: 21.1.2
See also
Possible workaround
Explicitly setting the const's concrete type instead of using the trait's associated type
impl Foo for Bar {
type AssocType = u32;
const THE_CONST: u32 = 1;
}
yields a more reasonable representation in the doc:

Consider the following code as
lib.rs:Running
cargo docand opening the generated html, one seesNote
Instead of the more reasonably expected
or, barring that, just nothing instead of the confusing
transmutestring.Meta
rustc --version --verbose:See also
Possible workaround
Explicitly setting the const's concrete type instead of using the trait's associated type
yields a more reasonable representation in the doc:
