Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0369: binary operation cannot be applied to type

What it meansAn operator like + or == was used on a type that does not implement it.

What rustc prints

error[E0369]: no implementation for `f32 << {integer}`
 --> main.rs:6:3
  |
6 | x << 2;
  | - ^^ - {integer}
  | |
  | f32

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

Why it happens

  • Comparing structs with == without #[derive(PartialEq)].
  • Adding two &str values (use format! or a String).

How to fix it

1. Derive or implement the operator trait

#[derive(PartialEq)]
struct Id(u32);

2. Build a String

let full = format!("{first} {last}");

Other wordings of this error

binary operation cannot be applied to type, cannot be applied to type, no implementation for

E0369Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

A binary operation was attempted on a type which doesn't support it.

Erroneous code example:

let x = 12f32; // error: binary operation `<<` cannot be applied to
               //        type `f32`

x << 2;

To fix this error, please check that this type implements this binary operation. Example:

let x = 12u32; // the `u32` type does implement it:
               // https://doc.rust-lang.org/stable/std/ops/trait.Shl.html

x << 2; // ok!

It is also possible to overload most operators for your own type by implementing traits from std::ops.

String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left. If something should be added to a string literal, move the literal to the heap by allocating it with to_owned() like in "Your text".to_owned().

From rustc --explain E0369 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ