about summary refs log tree commit diff
path: root/tests/ui/type/mutually-recursive-types.rs
blob: 5472e1582218e01c4f92abb1cf8d69b8bcbb9f42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Test that mutually recursive type definitions are properly handled by the compiler.
//! This checks that types can reference each other in their definitions through
//! `Box` indirection, creating cycles in the type dependency graph.

//@ run-pass

#[derive(Debug, PartialEq)]
enum Colour {
    Red,
    Green,
    Blue,
}

#[derive(Debug, PartialEq)]
enum Tree {
    Children(Box<List>),
    Leaf(Colour),
}

#[derive(Debug, PartialEq)]
enum List {
    Cons(Box<Tree>, Box<List>),
    Nil,
}

#[derive(Debug, PartialEq)]
enum SmallList {
    Kons(isize, Box<SmallList>),
    Neel,
}

pub fn main() {
    // Construct and test all variants of Colour
    let _ = Tree::Leaf(Colour::Red);

    let _ = Tree::Leaf(Colour::Green);

    let _ = Tree::Leaf(Colour::Blue);

    let _ = List::Nil;

    let _ = Tree::Children(Box::new(List::Nil));

    let _ = List::Cons(Box::new(Tree::Leaf(Colour::Blue)), Box::new(List::Nil));

    let _ = SmallList::Kons(42, Box::new(SmallList::Neel));
}