#E0145: 不是由其模組定義的具名 some 型別
type X = some Tr; 是一個具體型別,由 X 所在模組中回傳 X 的函式(fn make() -> X { .. })從其主體提供。這個模組沒有這樣的函式、這些函式提供了不同的型別,或其中一個是泛型函式。在該模組中加入回傳 X 的函式、讓每個函式都回傳相同的型別(讓其他函式呼叫第一個),或不要讓型別參數出現在其中:泛型的不透明結果寫成 fn f<T>(..) -> some Tr。
nabi
type Evens = some Iterator<Item = i64>;
println("no evens yet");
error[E0145]: `Evens` has no defining function --> main.nabi:1:1 | 1 | type Evens = some Iterator<Item = i64>; | ^^^^ | = help: a function in this module that returns `Evens` gives its type: `fn make() -> Evens { .. }`
加入回傳它的函式:
nabi
type Evens = some Iterator<Item = i64>;
fn evens(n: i64) -> Evens {
(0..n).filter(|x| x % 2 == 0)
}
println(evens(7).count());
4
相關錯誤碼:E0069 未滿足 trait 約束、E0146 把具名 some 型別當作其具體型別使用
發現錯誤? 在 GitHub 上編輯此頁 最後更新: