Static rustc_lint::builtin::BINDINGS_WITH_VARIANT_NAME
source · pub static BINDINGS_WITH_VARIANT_NAME: &'static Lint
Expand description
The bindings_with_variant_name
lint detects pattern bindings with
the same name as one of the matched variants.
Example
ⓘ
pub enum Enum {
Foo,
Bar,
}
pub fn foo(x: Enum) {
match x {
Foo => {}
Bar => {}
}
}
{{produces}}
Explanation
It is usually a mistake to specify an enum variant name as an
identifier pattern. In the example above, the match
arms are
specifying a variable name to bind the value of x
to. The second arm
is ignored because the first one matches all values. The likely
intent is that the arm was intended to match on the enum variant.
Two possible solutions are:
- Specify the enum variant using a path pattern, such as
Enum::Foo
. - Bring the enum variants into local scope, such as adding
use Enum::*;
to the beginning of thefoo
function in the example above.