E0006#
Warning name: unused_constructor
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
Ais never constructed, it means there is noA(...).If a variant is unused, it means it is never constructed and never read.
Erroneous example#
///|
priv enum T {
A
B
C
}
///|
pub fn f() -> Unit {
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.///| priv enum T { A B C } ///| pub fn f() -> Unit { 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
pubkeyword to the enum definition. Notice this will make the implementation of the variant visible to the users of the package.///| pub enum T2 { A B C } ///| pub fn T2::new(value : Int) -> T2 { match value { 0 => T2::A 1 => T2::B _ => T2::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 T3 { A B C }
If some variants are indeed useless, you can remove the unused variants.
///| priv enum T4 { A } ///| pub fn g() -> Unit { match T4::A { A => () } }