error[E0369]: binary operation `==` cannot be applied to type (Rust) — how to fix
error[E0369]: binary operation `==` cannot be applied to type `Point`
error[E0369]: cannot add `T` to `T`
error[E0369]: cannot add `&str` to `&str`
Quick fix: For your own structs/enums add #[derive(PartialEq)] (and PartialOrd) or implement std::ops::Add. For generics add a bound: fn sum<T: Add<Output = T>>(a: T, b: T) -> T. For strings use a.to_owned() + b or format!("{a}{b}").
What it means
Every operator maps to a trait:
| Operator | Trait |
|---|---|
== != |
PartialEq |
< > <= >= |
PartialOrd |
+ - * / % |
Add Sub Mul Div Rem (in std::ops) |
+= etc. |
AddAssign etc. |
E0369 means the left-hand type has no implementation of that trait (for that right-hand type). The compiler's note usually says which trait is missing, e.g. "an implementation of PartialEq might be missing for Point".
Cause 1: comparing your own type
struct Point { x: i32, y: i32 }
if a == b { } // E0369
Derive the comparison traits:
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct Point { x: i32, y: i32 }
Deriving requires every field to implement the trait too. f32/f64 fields implement PartialEq and PartialOrd but not Eq/Ord, so derive only the partial ones for such structs.
Enums work the same way. To check a variant without deriving, use pattern matching:
if matches!(state, State::Ready) { }
Cause 2: generic function without a trait bound
fn largest<T>(a: T, b: T) -> T {
if a > b { a } else { b } // E0369: binary operation `>` cannot be applied to type `T`
}
Tell the compiler T supports the operator:
fn largest<T: PartialOrd>(a: T, b: T) -> T {
if a > b { a } else { b }
}
use std::ops::Add;
fn sum<T: Add<Output = T>>(a: T, b: T) -> T {
a + b
}
For references (&a + &b), the bound goes on the reference type: where for<'a> &'a T: Add<&'a T, Output = T>. Often simpler: require T: Copy and work with values.
Cause 3: adding string slices
let s = "hello " + "world"; // E0369: cannot add `&str` to `&str`
+ on strings is only String + &str. Options:
let s = String::from("hello ") + "world";
let s = format!("{}{}", a, b);
let s = [a, b].concat();
let mut s = a.to_owned(); s.push_str(b);
String + String is a different error (E0308, expected &str); write s1 + &s2.
Cause 4: implement the operator yourself
For math-like types (vectors, money, matrices):
use std::ops::Add;
#[derive(Debug, Clone, Copy, PartialEq)]
struct Vec2 { x: f64, y: f64 }
impl Add for Vec2 {
type Output = Vec2;
fn add(self, o: Vec2) -> Vec2 {
Vec2 { x: self.x + o.x, y: self.y + o.y }
}
}
To support Vec2 * f64, implement Mul<f64> for Vec2. Operators are not automatically symmetric: f64 * Vec2 needs its own impl Mul<Vec2> for f64.
Cause 5: mismatched operand types
Comparing Option<T> with T, or &T with T, may also report E0369 or E0277 depending on the types:
if opt == Some(5) { } // compare Option with Option
if *r == 5 { } // dereference the reference
If the compiler suggests a trait that isn't operator-related, see E0277 trait bound not satisfied.
Last updated 2026-12-05.