E1006

E1006#

Variant is never read, never constructed, or both.

  • If a variant is never read, it means it is defined but never destructed in a pattern matching expression (match, let, guard let, loop function, etc.).

  • If a variant A is never constructed, it means there is no A(...).

  • If a variant is unused, it means it is never constructed and never read.

Erroneous example#

priv enum T {
  A // Warning: Variant 'A' is never read
  B // Warning: Variant 'B' is never constructed
  C // Warning: Variant 'C' is unused
}

fn main {
  match T::A {
    B => ()
    _ => ()
  }
}

Suggestion#

  • If some variants are never read, while others are read, this means that you have use wildcard pattern (_) in your code. You can expand the wildcard pattern to include the unused variants.

    fn main {
      match T::A {
        B => ()
        C => ()
        A => ()
      }
    }
    
  • If all variants are never read, and you need to read these variants outside of current package, you can add pub keyword to the enum definition. Notice this will make the implementation of the variant visible to the users of the package.

    pub enum T {
      A
      B
      C
    }
    
  • If you need to construct the "never constructed" variant outside of the current package, you can add pub(all) keyword to the variant.

    pub(all) enum T {
      A
      B
      C
    }
    
  • If some variants are indeed useless, you can remove the unused variants.

    enum T {
      A
      B
    }