#E0093: 泛型實例化過深
實例化一個泛型函式時,它不斷以越來越大的型別實例化自己。請打斷這個遞迴,例如改用 any 參數。
nabi
fn nest<T>(x: T, n: i32) -> i32 {
if n == 0 { return 0; }
nest((x, x), n - 1)
}
println(f"{nest(1, 3)}");
error[E0093]: instantiating generic function `nest` recursed past the limit (depth 64) - the instantiation never reaches a fixed point --> main.nabi:3:5 | 3 | nest((x, x), n - 1) | ^^^^^^^^^^^^^^^^^^^
改用 any 接受任意型別的值,而不是型別參數:
nabi
fn nest(x: any Debug, n: i32) -> i32 {
if n == 0 { return 0; }
nest(x, n - 1)
}
println(f"{nest(1, 3)}");
0
相關錯誤碼:E0095 型別過大
發現錯誤? 在 GitHub 上編輯此頁 最後更新: