generalize bindings_with_variant_name lint
This commit is contained in:
parent
900811e430
commit
71450c7aad
@ -67,18 +67,13 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
|
||||
hir::LocalSource::AwaitDesugar => ("`await` future binding", None),
|
||||
};
|
||||
self.check_irrefutable(&loc.pat, msg, sp);
|
||||
|
||||
// Check legality of move bindings and `@` patterns.
|
||||
self.check_patterns(false, &loc.pat);
|
||||
}
|
||||
|
||||
fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) {
|
||||
intravisit::walk_body(self, body);
|
||||
|
||||
for param in body.params {
|
||||
self.check_irrefutable(¶m.pat, "function argument", None);
|
||||
self.check_patterns(false, ¶m.pat);
|
||||
}
|
||||
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
|
||||
intravisit::walk_param(self, param);
|
||||
self.check_irrefutable(¶m.pat, "function argument", None);
|
||||
self.check_patterns(false, ¶m.pat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,6 +118,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
|
||||
if !self.tcx.features().bindings_after_at {
|
||||
check_legality_of_bindings_in_at_patterns(self, pat);
|
||||
}
|
||||
check_for_bindings_named_same_as_variants(self, pat);
|
||||
}
|
||||
|
||||
fn check_match(
|
||||
@ -132,11 +128,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
|
||||
source: hir::MatchSource,
|
||||
) {
|
||||
for arm in arms {
|
||||
// First, check legality of move bindings.
|
||||
// Check the arm for some things unrelated to exhaustiveness.
|
||||
self.check_patterns(arm.guard.is_some(), &arm.pat);
|
||||
|
||||
// Second, perform some lints.
|
||||
check_for_bindings_named_same_as_variants(self, &arm.pat);
|
||||
}
|
||||
|
||||
let module = self.tcx.hir().get_module_parent(scrut.hir_id);
|
||||
|
@ -25,6 +25,16 @@ fn main() {
|
||||
//~^^^ WARN unused variable: `Foo`
|
||||
}
|
||||
|
||||
let Foo = foo::Foo::Foo;
|
||||
//~^ ERROR variable `Foo` should have a snake case name
|
||||
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
|
||||
//~^^^ WARN unused variable: `Foo`
|
||||
|
||||
fn in_param(Foo: foo::Foo) {}
|
||||
//~^ ERROR variable `Foo` should have a snake case name
|
||||
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
|
||||
//~^^^ WARN unused variable: `Foo`
|
||||
|
||||
test(1);
|
||||
|
||||
let _ = Something { X: 0 };
|
||||
|
@ -6,6 +6,18 @@ LL | Foo => {}
|
||||
|
|
||||
= note: `#[warn(bindings_with_variant_name)]` on by default
|
||||
|
||||
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
|
||||
--> $DIR/lint-uppercase-variables.rs:28:9
|
||||
|
|
||||
LL | let Foo = foo::Foo::Foo;
|
||||
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
|
||||
|
||||
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
|
||||
--> $DIR/lint-uppercase-variables.rs:33:17
|
||||
|
|
||||
LL | fn in_param(Foo: foo::Foo) {}
|
||||
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
|
||||
|
||||
warning: unused variable: `Foo`
|
||||
--> $DIR/lint-uppercase-variables.rs:22:9
|
||||
|
|
||||
@ -19,6 +31,18 @@ LL | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
|
||||
|
||||
warning: unused variable: `Foo`
|
||||
--> $DIR/lint-uppercase-variables.rs:28:9
|
||||
|
|
||||
LL | let Foo = foo::Foo::Foo;
|
||||
| ^^^ help: consider prefixing with an underscore: `_Foo`
|
||||
|
||||
warning: unused variable: `Foo`
|
||||
--> $DIR/lint-uppercase-variables.rs:33:17
|
||||
|
|
||||
LL | fn in_param(Foo: foo::Foo) {}
|
||||
| ^^^ help: consider prefixing with an underscore: `_Foo`
|
||||
|
||||
error: structure field `X` should have a snake case name
|
||||
--> $DIR/lint-uppercase-variables.rs:10:5
|
||||
|
|
||||
@ -49,6 +73,18 @@ error: variable `Foo` should have a snake case name
|
||||
LL | Foo => {}
|
||||
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: variable `Foo` should have a snake case name
|
||||
--> $DIR/lint-uppercase-variables.rs:28:9
|
||||
|
|
||||
LL | let Foo = foo::Foo::Foo;
|
||||
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`
|
||||
|
||||
error: variable `Foo` should have a snake case name
|
||||
--> $DIR/lint-uppercase-variables.rs:33:17
|
||||
|
|
||||
LL | fn in_param(Foo: foo::Foo) {}
|
||||
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0170`.
|
||||
|
Loading…
Reference in New Issue
Block a user