Skip to content

Stack overflow on recursive type #25439

Closed
@terpstra

Description

@terpstra

I was trying to write a statically dispatched fixed-point function (aka Y combinator) in rust. My hope was to use it to make recursive closures. While implementing it, I triggered a compiler stack overflow which can be reproduced with this small example code:

struct Helper<'a,F:'a>(&'a F);

fn fix<F>(f: F) -> i32
  where F: Fn(Helper<F>, i32) -> i32      
{
  f(Helper(&f), 8) 
}

fn main() {  
  fix(|_,x| x);  
}

This was on "rustc 1.0.0-beta (9854143 2015-04-02) (built 2015-04-02)", but it still happens on nightly.

I've seen there are a couple other stack overflow bugs related to recursive types. The examples I saw, however, were situations where the compiler should have just given a nicer error message. In my case, I think this is a legitimate piece of code that should compile.

This is analagous to the SML datatype 'a t = T of 'a t -> 'a

Rust should be able to do this, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions