Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0275: overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<_>>>>>>>: Foo`
What it meansAn evaluation of a trait requirement overflowed.
What rustc prints
error[E0275]: overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<_>>>>>>>: Foo` --> main.rs:5:33 | 5 | impl<T> Foo for T where Bar<T>: Foo {} | ^^^ | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`main`) note: required for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<_>>>>>>>>>>>>>` to implement `Foo` --> main.rs:5:9 | 5 | impl<T> Foo for T where Bar<T>: Foo {} | ^^^ ^ --- unsatisfied trait bound introduced here = note: 126 redundant requirements hidden = note: required for `Bar<T>` to implement `Foo` = note: the full name for the type has been written to 'C:\Users\Matthew\AppData\Local\Temp\rerr-t1v_0c9_\out.long-type-5365014652263787654.txt' = note: consider using `--verbose` to print the full type name to the console
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
An evaluation of a trait requirement overflowed.
Erroneous code example:
trait Foo {}
struct Bar<T>(T);
impl<T> Foo for T where Bar<T>: Foo {}
This error occurs when there was a recursive trait requirement that overflowed before it could be evaluated. This often means that there is an unbounded recursion in resolving some type bounds.
To determine if a T is Foo, we need to check if Bar<T> is Foo. However, to do this check, we need to determine that Bar<Bar<T>> is Foo. To determine this, we check if Bar<Bar<Bar<T>>> is Foo, and so on. This is clearly a recursive requirement that can't be resolved directly.
Consider changing your trait bounds so that they're less self-referential.
From rustc --explain E0275 (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
- E0225only auto traits can be used as additional traits in a trait object
- E0271type mismatch resolving `<i8 as Trait>::AssociatedType == u32`
- E0276impl has stricter requirements than trait
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?