#E0146: 把具名 some 类型当作其具体类型使用
在声明 type X = some Tr; 的模块之外,X 是一个只具有 Tr 的独立类型:它的具体类型不能写出,其他类型的值也不是 X。把值保留为 X(字段、let x: X、List<X> 和参数都可以持有它),通过 Tr 使用它,并从 X 所在模块的函数获取新的值。需要具体类型的代码放在那个模块中。
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: i64 = shapes::count();
error[E0146]: mismatched types: `let n` expects `i64`, found `Count`: outside `shapes`, `Count` is opaque --> main.nabi:7:14 | 7 | let n: i64 = shapes::count(); | ^^^^^^^^^^^^^^^ | = help: only `shapes` sees what `Count` is: keep the value as `Count` and use it through its bounds, get one from `shapes::count`, or move this code into `shapes`
把它保留为 Count:
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: shapes::Count = shapes::count();
println(f"{n} shapes");
3 shapes
相关错误码:E0040 类型不匹配,E0145 具名 some 类型不是由其模块定义的
发现错误? 在 GitHub 上编辑此页 最后更新: