You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error: overflow evaluating the requirement <_ as core::iter::Iterator>::Item #23707
src/lib.rs:1:1: 1:1 error: overflow evaluating the requirement `<_ as core::iter::Iterator>::Item` [E0275
src/lib.rs:1 //!
^
The error suggests adding a recursion requirement to my crate root
note: consider adding a `#![recursion_limit="128"]` attribute to your crate
It continues to recommend doubling the recursion limit until I've raised it so high that rustc itself overflows it's stack
thread 'rustc' has overflowed its stack
Could not compile `mindtree_utils`.
Here's a link to the repository that is failing to build in case you would like to give it a go.
The error only appeared in the latest nightly for rustc (I'm fairly sure the crate was building fine before I updated). Here's the version of the nightly I've just downloaded which seems to have caused the failure:
Alright, I think I've found the culprit (playpen link).
/// A trait that produces a clone of the previously yielded element along/// with the current element.pubtraitZipPrev:Iterator + Sized{fnzip_prev(self) -> Items<Self::Item,Self>{Items{maybe_prev:None,iter:self,}}}/// The iterator produced by the zip_prev method.pubstructItems<A,I>{maybe_prev:Option<A>,iter:I,}impl<I>IteratorforItems<I::Item,I>whereI:Iterator,I::Item:Clone,{typeItem = (I::Item,Option<I::Item>);#[inline]fnnext(&mutself) -> Option<(I::Item,Option<I::Item>)>{letItems{refmut iter,refmut maybe_prev } = *self;ifletSome(item) = iter.next(){let old_maybe_prev = maybe_prev.take();*maybe_prev = Some(item.clone());Some((item, old_maybe_prev))}else{None}}}impl<I>ZipPrevforIwhereI:Iterator,I::Item:Clone{}fnmain(){}
Perhaps it's the implementation of Iterator for Items<I::Item, I> where I: Iterator that's causing the recursion? The crate that this came from was compiling a couple days ago (I've only made a couple changes to clean it up a bit before sharing).
We are having similar issues with rust-sessions. Here is the cooked down version:
use std::marker::{PhantomData,PhantomFn};structChan<T>(PhantomData<T>);structEps;structSend<A,R>(PhantomData<(A,R)>);traitDual:PhantomFn<Self>{}implDualfor(Eps,Eps){}impl<A,T>Dualfor(Send<A,T>,Send<A,T>)where(T,T):Dual{}fnrequest<R,S>(rx:Chan<R>)where(R,S):Dual{borrow_request(&rx)}fnborrow_request<R,S>(rx:&Chan<R>)where(R,S):Dual{}
That code compiles with rustc 1.0.0-dev (d5408f376 2015-03-19) but not with rustc 1.0.0-dev (b0fd67b3e 2015-03-26)
Here's another example. This fails with overflow evaluating '_ : core::marker::Sized'. Commenting one line in main and uncommenting its alternative makes the code compile.
Here's another one that overflows. Is it supposed to? (and if not, is there a workaround?)
traitX{typeItem;}traitY{typeItem:X;}impl<T:Y>XforT{typeItem = <Self::ItemasX>::Item;}// error[E0275]: overflow evaluating the requirement `<T as X>::Item`// --> src/main.rs:9:12// |// 9 | impl<T: Y> X for T {// | ^ ^
It seems like this is happening whenever an associated type is referenced while it's still evaluating the impl it's defined in, here is a small example that seems like it should be fine:
Intuitively it seems like the overflow might be comming from infinite recursion when it tries to check the impl TraitWithAssociatedType, which requires it to evaluate Self::AssociatedType to see whether it should apply to StructWithImpl, but that means it tries to first evaluate the whole impl TraitWithAssociatedType to get AssociatedType, even if it could just use the definition type AssociatedType = AnyStruct. (Might be wrong about this, I'm not a compiler writer, that's just what seems to make sense to me.)
In this case replacing Self::AssociatedType with AnyStruct fixes the problem, but that means writing the type out in full, and there might be some places where that is either not possible or requires a lot of duplication.
Activity
steveklabnik commentedon Mar 26, 2015
Can you show some code that reproduces this?
mitchmindtree commentedon Mar 26, 2015
Alright, I think I've found the culprit (playpen link).
Perhaps it's the implementation of
Iterator for Items<I::Item, I> where I: Iteratorthat's causing the recursion? The crate that this came from was compiling a couple days ago (I've only made a couple changes to clean it up a bit before sharing).Munksgaard commentedon Mar 26, 2015
We are having similar issues with rust-sessions. Here is the cooked down version:
That code compiles with
rustc 1.0.0-dev (d5408f376 2015-03-19)but not withrustc 1.0.0-dev (b0fd67b3e 2015-03-26)cc @laumann
Gerstacker commentedon Apr 3, 2015
Here's another example. This fails with overflow evaluating '_ : core::marker::Sized'. Commenting one line in main and uncommenting its alternative makes the code compile.
https://gist.github.com/Gerstacker/b402c38381604e2ff117
In playpen:
http://is.gd/0bkFkN
laumann commentedon Apr 9, 2015
What's the status of this?
The example @Munksgaard posts can be "fixed" by adding explicit type annotations to the call to
borrow_request(), iebut it's rather unsatisfactory, since whoever calls
request()will also be forced to explicitly annotate the function call (and so on).Gerstacker commentedon Apr 9, 2015
This annotation workaround fixed mine as well, letting rustc get far enough to expose an embarrassing problem in my code.
Munksgaard commentedon Apr 12, 2015
It seems like PR #23580 is the cause of this issue. Perhaps @nikomatsakis could comment on whether or not this is intentional?
Munksgaard commentedon Apr 12, 2015
Specifically, 809a554 compiles my above snippet while 76ead08 doesn't.
23707
steveklabnik commentedon Nov 6, 2015
This no longer ICEs.
14 remaining items
brson commentedon Jun 27, 2016
Triage: @bluss example still overflows.
earthengine commentedon May 7, 2018
Not sure if this is relevant, but a popular lib
tokioseems triggers this error when used withRcin a certain way.Stackoverflow question
The workaround is to use
But for new users this will just get them confused.
aldanor commentedon Jan 1, 2019
Here's another one that overflows. Is it supposed to? (and if not, is there a workaround?)
marmeladema commentedon Nov 21, 2019
Another somehow simple example:
LukeMiles49 commentedon Jul 11, 2020
It seems like this is happening whenever an associated type is referenced while it's still evaluating the impl it's defined in, here is a small example that seems like it should be fine:
Intuitively it seems like the overflow might be comming from infinite recursion when it tries to check the
impl TraitWithAssociatedType, which requires it to evaluateSelf::AssociatedTypeto see whether it should apply toStructWithImpl, but that means it tries to first evaluate the wholeimpl TraitWithAssociatedTypeto getAssociatedType, even if it could just use the definitiontype AssociatedType = AnyStruct. (Might be wrong about this, I'm not a compiler writer, that's just what seems to make sense to me.)In this case replacing
Self::AssociatedTypewithAnyStructfixes the problem, but that means writing the type out in full, and there might be some places where that is either not possible or requires a lot of duplication.Rollup merge of rust-lang#132312 - jieyouxu:delete-crashes-23707, r=m…
Unrolled build for rust-lang#132312