E0277
RustERRORCommonTraits

Trait bound not satisfied

Quick Answer

Implement the missing trait for your type, or add a where clause that constrains the generic to only types that implement it.

What this means

A type used in a generic context does not implement the required trait. This is the primary compiler error for generic programming mistakes in Rust.

Why it happens
  1. 1Passing a type to a generic function whose where clause requires a trait the type doesn't implement
  2. 2Using a type that doesn't implement Display with println!("{}", ...)

Fix 1

Implement the required trait

Implement the required trait
use std::fmt;

struct Point { x: f64, y: f64 }

// Implement Display to use with println!("{}", ...)
impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({}, {})", self.x, self.y)
    }
}

Why this works

Implementing Display satisfies the fmt::Display bound required by println!, format!, and similar macros.

Fix 2

Add a trait bound to your generic

Add a trait bound to your generic
use std::fmt::Display;

fn print_item<T: Display>(item: T) {
    println!("{}", item);
}

Why this works

Constraining the generic with T: Display ensures only types with Display are accepted, making the trait requirement explicit at the call site.

Code examples
Triggerrust
struct Foo;
println!("{}", Foo); // error[E0277]: Foo doesn't implement Display
Derive common traitsrust
#[derive(Debug, Clone, PartialEq)]
struct Point { x: f64, y: f64 }
Sources
Official documentation ↗

Rust Compiler Error Index

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Rust errors