#E0080: 定义依赖自身
常量、静态变量或类型别名直接或间接地用自身来定义,或者某个类型按值包含自身。打破这个循环;包含自身的类型要通过 List 这样的引用类型来持有它。
nabi
struct Node { value: i32; next: Node; }
error[E0080]: recursive type `Node` has infinite size (a struct can't contain itself by value; hold it through a reference type such as `List`) --> main.nabi:1:1 | 1 | struct Node { value: i32; next: Node; } | ^^^^^^
通过 List 这样的引用类型持有内层的值:
nabi
struct Node { value: i32; next: List<Node>; }
let n = Node { value: 1, next: [] };
println(f"{n.value}");
1
相关错误码:E0079 无法在编译时求值,E0095 类型过大
发现错误? 在 GitHub 上编辑此页 最后更新: