E0003

E0003#

Warning name: unused_type_declaration

Unused type declaration.

This type is not used by any other part of your code, which means it's not constructed nor consumed, and others can't construct nor consume due to visibility. Type declaration is by default abstract, which means it is publicly visible to users of this package, but they cannot construct nor destruct the type. Therefore, this warning is only shown if the type has abstract or private visibility, and is not constructed nor consumed by any other part of this package.

Note that this warning might uncover other bugs in your code. For example, if there are two types in the package that has similar name, you might just use the other type by mistake.

Erroneous example#

///|
struct Foo {
  bar : Int
}

///|
pub fn f() -> Unit {
  struct Bar {
    foot : Int
  }

}

Suggestion#

There are multiple ways to fix this warning:

  • If the type is indeed useless, you can remove the definition of the type.

  • If this type is not local, and is part of the public API of your module, you can add pub or pub(all) visibility keyword from the type.

    ///|
    pub struct Foo {
      bar : Int
    }
    
  • Check if you are referencing the type with a correct name.

It is rather rare to have a type that is private and unused at the same time; therefore, we suggest you remove the type if it is not used.