Skip to content

"error: illegal recursive type" #19601

@anishathalye

Description

@anishathalye

Is the restriction on recursive types really necessary?

It makes sense with structs, because recursive structs would mean infinite-sized structs. But with types, it seems unnecessary. After a brief discussion on the Rust IRC, someone told me that this is probably a bug.

Reduced Test Case

trait A<T> {}

trait DoesAforB<T> {}

// no way to express
// struct B<T> where B<T>: A<B<T>>;

struct B<T: DoesAforB<B<T>>>;

fn main() {}

Output

rec.rs:8:23: 8:27 error: illegal recursive type; insert an enum or struct in the cycle, if this is desired
rec.rs:8 struct B<T: DoesAforB<B<T>>>;
                               ^~~~

rustc version

rustc 0.13.0-nightly (336349c93 2014-11-17 20:37:19 +0000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions