From 8307f972537815cc5870aeb7d2866756821b7675 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 20 Apr 2025 19:24:23 +0200 Subject: [PATCH] Check bare function idents for non snake-case name --- compiler/rustc_lint/src/nonstandard_style.rs | 10 ++++++++++ .../ui/lint/non-snake-case/lint-uppercase-variables.rs | 3 +++ .../non-snake-case/lint-uppercase-variables.stderr | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index a3e7c84584d30..d1138e8f1fa53 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -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); diff --git a/tests/ui/lint/non-snake-case/lint-uppercase-variables.rs b/tests/ui/lint/non-snake-case/lint-uppercase-variables.rs index 59dba536f24b6..aefbe63606a14 100644 --- a/tests/ui/lint/non-snake-case/lint-uppercase-variables.rs +++ b/tests/ui/lint/non-snake-case/lint-uppercase-variables.rs @@ -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 }; diff --git a/tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr b/tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr index 9220828014fda..b0c56003957c9 100644 --- a/tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr +++ b/tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr @@ -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`.