Skip to content

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.

EXAMPLE: CI-CHECKED FAILURECOMPILE-FAIL ASSERTED · examples/compile-fail/debug-not-implemented.rs#debug-not-implemented
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.

For ordinary structs and enums, deriving Debug is usually the simplest fix.

EXAMPLE: CI-CHECKEDTEST ASSERTED · examples/format-output/src/error_pages.rs#error-debug-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.

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.

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.