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.
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
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0223ambiguous associated type
- E0224at least one trait is required for an object type
- E0271type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
- E0275overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<_>>>>>>>: Foo`
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?