E1005

E1005#

Unused generic type variable.

In some cases, using types with unused generic type variables will make it impossible for the type checker to infer the type of the unused variable. This might lead to cryptic error messages, even unexpected runtime behavior.

Erroneous example#

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)
}

Suggestion#

  • If the type variable is indeed useless, remove the unused type variable.

    struct Foo { // Remove the unused type variable.
      bar : Int
    }
    
  • If you wish to keep the type variable, you can use _ to indicate that the type variable is intentionally unused.

    struct Foo[_] {
      bar : Int
    }