Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type expansion does not terminate when faced with erroneous recursive associated types #22672

Closed
knz opened this Issue Feb 22, 2015 · 5 comments

Comments

Projects
None yet
5 participants
@knz
Copy link

knz commented Feb 22, 2015

rustc does not terminate (or will perhaps terminate with a stack overflow given sufficient time and insufficient memory) when provided the following code as input:

use std::marker::PhantomFn;
trait TypeTrans<X> : PhantomFn<(Self,X)> { type Y; }
trait Circular  : PhantomFn<Self> { 
  type T : Circular;  
}
impl<X, U : Circular> TypeTrans<X> for U {
  type Y = < <U as Circular>::T as TypeTrans<X> >::Y;
}
fn main()  {}

I expected an error message stating that the expansion recursion depth limit was exceeded (like when one makes such a mistake with C++ templates).

Instead, rustc does not terminate, and attaching gdb reveals an ever growing call stack (see backtrace below).

Meta

rustc --version --verbose:

rustc 1.0.0-dev (2b01a37ec 2015-02-21) (built 2015-02-21)
binary: rustc
commit-hash: 2b01a37ec38db9301239f0c0abcf3c695055b0ff
commit-date: 2015-02-21
build-date: 2015-02-21
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev

Backtrace:

#0  0x00007ffff5431340 in middle::subst::EnumeratedItems$LT$$u27$a$C$$u20$T$GT$.Iterator::next::h1346200232120614734 ()   from /scratch/opt/lib/librustc-4e7c5e5c.so
#1  0x00007ffff5430c18 in middle::ty_fold::TypeFolder::fold_substs::h2872510736836719091 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#2  0x00007ffff5431468 in middle::ty_fold::super_fold_trait_ref::h8139351459621092501 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#3  0x00007ffff5430655 in middle::ty_fold::TypeFolder::fold_ty::h6033027339639275593 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#4  0x00007ffff5430c5a in middle::ty_fold::TypeFolder::fold_substs::h2872510736836719091 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#5  0x00007ffff5431468 in middle::ty_fold::super_fold_trait_ref::h8139351459621092501 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#6  0x00007ffff5430655 in middle::ty_fold::TypeFolder::fold_ty::h6033027339639275593 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#7  0x00007ffff5430c5a in middle::ty_fold::TypeFolder::fold_substs::h2872510736836719091 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#8  0x00007ffff5431468 in middle::ty_fold::super_fold_trait_ref::h8139351459621092501 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#9  0x00007ffff5430655 in middle::ty_fold::TypeFolder::fold_ty::h6033027339639275593 () from /scratch/opt/lib/librustc-4e7c5e5c.so
#10 0x00007ffff5430c5a in middle::ty_fold::TypeFolder::fold_substs::h2872510736836719091 () from /scratch/opt/lib/librustc-4e7c5e5c.so
....
@apasel422

This comment has been minimized.

Copy link
Member

apasel422 commented Jul 28, 2015

This is still an issue after removing the outdated PhantomFn bounds.

@Zaerei

This comment has been minimized.

Copy link

Zaerei commented Sep 22, 2015

Yup, still an issue, I just spent a while debugging a cryptic "rustc overflowed its stack" bug, it would be useful if, when this can be detected, we could print a more specific error message on accidental circular type references.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Mar 9, 2017

Old type checking bug. P-tag?

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Mar 9, 2017

This is still an issue after removing the outdated PhantomFn bounds.

Not any more:

C:\Users\steve\tmp> rustc .\foo.rs
error[E0275]: overflow evaluating the requirement `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<U as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T as Circular>::T`
 --> .\foo.rs:5:23
  |
5 | impl<X, U : Circular> TypeTrans<X> for U {
  |                       ^^^^^^^^^^^^
  |
  = help: consider adding a `#![recursion_limit="128"]` attribute to your crate

given

I expected an error message stating that the expansion recursion depth limit was exceeded (like when one makes such a mistake with C++ templates).

I agree, and this is fixed.

@knz

This comment has been minimized.

Copy link
Author

knz commented Mar 9, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.