E0007#
Warning name: unused_field
Field is never read. This include fields in structs and fields in enum constructors.
Erroneous example#
///|
priv enum E {
A(Int)
B(value~ : Int)
}
///|
priv struct S {
value : Int
}
///|
test {
ignore(B(value=1))
match A(1) {
A(_) => println("A")
B(_) => println("B")
}
ignore(S::{ value : 1 })
}
Suggestion#
If the fields in enum constructors are unused, you can expand them in the pattern to use them:
///| priv enum E { A(Int) B(value~ : Int) } ///| priv struct S { value : Int } ///| test { ignore(B(value=1)) match A(1) { A(x) => inspect("A(\{x})", content="A(1)") B(value~) => inspect("B(\{value})") } let s = S::{ value: 1 } match s { { value } => println("S(\{value})") } println("S(\{s.value})") }
If the fields are indeed useless, you can remove the field from the constructor:
///| priv enum E2 { A2 B2 } ///| priv struct S2 {} ///| test { ignore(E2::B2) match E2::A2 { A2 => println("A") B2 => println("B") } ignore(S2::{ }) }
If the fields are expected to be used by the others, you can mark the type as
puborpub(all).///| pub enum E3 { A3(Int) B3(value~ : Int) } ///| pub struct S3 { value : Int }