Rollup merge of #140090 - Urgau:snake_case-fn-var, r=petrochenkov
Check bare function idents for non snake-case name This PR adds the check required to lint on bare function idents for non snake-case name. Reported at #140089. cc `@theemathas`
This commit is contained in:
@@ -422,6 +422,16 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_, hir::AmbigArg>) {
|
||||
if let hir::TyKind::BareFn(hir::BareFnTy { param_idents, .. }) = &ty.kind {
|
||||
for param_ident in *param_idents {
|
||||
if let Some(param_ident) = param_ident {
|
||||
self.check_snake_case(cx, "variable", param_ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(param_idents)) = item.kind {
|
||||
self.check_snake_case(cx, "trait method", &item.ident);
|
||||
|
||||
@@ -35,6 +35,9 @@ fn main() {
|
||||
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
|
||||
//~^^^ WARN unused variable: `Foo`
|
||||
|
||||
let _: fn(CamelCase: i32);
|
||||
//~^ ERROR variable `CamelCase` should have a snake case name
|
||||
|
||||
test(1);
|
||||
|
||||
let _ = Something { X: 0 };
|
||||
|
||||
@@ -85,6 +85,12 @@ error: variable `Foo` should have a snake case name
|
||||
LL | fn in_param(Foo: foo::Foo) {}
|
||||
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`
|
||||
|
||||
error: aborting due to 9 previous errors; 3 warnings emitted
|
||||
error: variable `CamelCase` should have a snake case name
|
||||
--> $DIR/lint-uppercase-variables.rs:38:15
|
||||
|
|
||||
LL | let _: fn(CamelCase: i32);
|
||||
| ^^^^^^^^^ help: convert the identifier to snake case: `camel_case`
|
||||
|
||||
error: aborting due to 10 previous errors; 3 warnings emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0170`.
|
||||
|
||||
Reference in New Issue
Block a user