#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 上編輯此頁 最後更新: