Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0225: only auto traits can be used as additional traits in a trait object

What it meansMultiple types were used as bounds for a closure or trait object.

What rustc prints

error[E0225]: only auto traits can be used as additional traits in a trait object
 --> main.rs:2:36
  |
2 |     let _: Box<dyn std::io::Read + std::io::Write>;
  |                    -------------   ^^^^^^^^^^^^^^ additional non-auto trait
  |                    |
  |                    first non-auto trait
  |
  = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: std::io::Read + std::io::Write {}`
  = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>

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.

E0225Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

Multiple types were used as bounds for a closure or trait object.

Erroneous code example:

fn main() {
    let _: Box<dyn std::io::Read + std::io::Write>;
}

Rust does not currently support this.

Auto traits such as Send and Sync are an exception to this rule: It's possible to have bounds of one non-builtin trait, plus any number of auto traits. For example, the following compiles correctly:

fn main() {
    let _: Box<dyn std::io::Read + Send + Sync>;
}

From rustc --explain E0225 (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