Rust E0277: type doesn't implement Debug
Rust reports E0277 when code requires a trait that the type does not implement. With {:?} formatting, the required trait is std::fmt::Debug.
struct Point {
x: i32,
}
fn main() {
let point = Point { x: 3 };
println!("{point:?}");
}The example above is intentionally rejected by the stable Rust compiler in CI.
Fix your own struct with derive(Debug)
Section titled “Fix your own struct with derive(Debug)”For ordinary structs and enums, deriving Debug is usually the simplest fix.
#[derive(Debug)]
pub struct DebugPoint {
pub x: i32,
}The standard library explicitly recommends deriving Debug in the general case. The resulting representation is for programmer-facing inspection, not a stable serialization format.
Generic code may need a Debug bound
Section titled “Generic code may need a Debug bound”E0277 can also appear even when every value you currently pass happens to implement Debug. A generic function using {:?} must state that requirement in its signature, for example with T: std::fmt::Debug or an equivalent where clause.
The compiler checks the generic function against all types allowed by its declared bounds. It does not infer a permanent Debug requirement merely from the types used at current call sites. This is the same trait-bound rule described by the official E0277 documentation.
When derive(Debug) is not enough
Section titled “When derive(Debug) is not enough”A derived implementation requires the fields that it formats to support Debug. If you need a deliberate programmer-facing representation, or need to control which fields participate, implement Debug manually using the formatter’s debug builders.
For normal inspection, see inspect values with Debug and dbg! and pretty Debug with {:#?}.
If the compiler instead says the type does not implement Display, see E0277: type doesn’t implement Display.