I'm getting an error[E0275]: overflow evaluating the requirement
on this simple code, and I don't know how to resolve it. The error message suggests adding a recursion limit attribute to the trait; however, when I add the attribute it produces a new error message and suggests I double the recursion limit until it is so large that rustc
overflows its stack. There are many other questions already about this error, but they seem different than my case.
struct Foo<T>(T);
impl<T> From<&'_ Foo<T>> for String
where
for<'a> &'a T: Into<String>,
{
fn from(s: &Foo<T>) -> String {
(&s.0).into()
}
}
fn main() {
println!("{}", String::from(&Foo(String::new())));
}
error[E0275]: overflow evaluating the requirement `String: From<&'a Foo<_>>`
--> src/main.rs:13:20
|
13 | println!("{}", String::from(&Foo(String::new())));
| ^^^^^^^^^^^^
|
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`playground`)
= note: required because of the requirements on the impl of `for<'a> Into<String>` for `&'a Foo<_>`
= note: required because of the requirements on the impl of `From<&'a Foo<Foo<_>>>` for `String`
= note: 126 redundant requirements hidden
= note: required because of the requirements on the impl of `From<&Foo<Foo<Foo<...>>>>` for `String`
See Question&Answers more detail:os