E1007

E1007#

Field is never read. This include fields in structs and fields in enum constructors.

Erroneous example#

For enum constructor fields:

enum E {
  A(Int) // Warning: The 1st positional argument of constructor 'A' is unused.
  B(value~ : Int) // Warning: Field 'value' of constructor 'B' is unused.
}

fn main {
  ignore(B(value=1))
  match A(1) {
    A(_) => println("A")
    B(_) => println("B")
  }
}

For struct fields:

struct S {
  value : Int // Warning: Field 'value' is never read
}

fn main {
  ignore(S::{ value : 1 })
}

Suggestion#

If the fields in enum constructors are unused, you can expand them in the pattern to use them:

fn main {
  // ...
  match A(1) {
    A(x) => println("A(\{x})")
    B(value~) => println("B(\{value})")
  }
}

If the fields in structs are unused, you can list them in record pattern, or use the dot-syntax to access them:

fn main {
  let s = S::{ value : 1 }
  match s {
    { value } => println("S(\{value})")
  }
  println("S(\{s.value})")
}

Or, if the fields are indeed useless, you can remove the field from the constructor:

enum E {
  A
  B
}
struct S {
}