E1005#
未使用的泛型类型变量。
在某些情况下,使用带有未使用的泛型类型变量的类型将使类型检查器无法推断未使用变量的类型。这可能导致难以理解的错误信息,甚至是意想不到的运行时行为。
错误示例#
struct Foo[T] { // Warning: Unused type variable 'T'.
bar : Int
}
fn main {
let foo : Foo[Int] = { bar : 42 }
let baz = { bar : 42 } // Warning: The type of this expression is Foo[_/0]
println(foo.bar)
println(baz.bar)
}
建议#
如果类型变量确实没有用,移除未使用的类型变量。
struct Foo { // Remove the unused type variable. bar : Int }
如果你希望保留类型变量,你可以使用
_
来表示类型变量是有意未使用的。struct Foo[_] { bar : Int }