diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-30 17:27:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-30 17:27:58 +0200 |
| commit | 230215f89063b74d1f388ce157fab80bcad2675f (patch) | |
| tree | 6fd0e22088f471461b27960cb3c87b77bebeb58b | |
| parent | bc99a045cb0786b8a6f92abc5e80acd04dc74886 (diff) | |
| parent | 8307f972537815cc5870aeb7d2866756821b7675 (diff) | |
| download | rust-230215f89063b74d1f388ce157fab80bcad2675f.tar.gz rust-230215f89063b74d1f388ce157fab80bcad2675f.zip | |
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`
| -rw-r--r-- | compiler/rustc_lint/src/nonstandard_style.rs | 10 | ||||
| -rw-r--r-- | tests/ui/lint/non-snake-case/lint-uppercase-variables.rs | 3 | ||||
| -rw-r--r-- | tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr | 8 |
3 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index a3e7c84584d..d1138e8f1fa 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 59dba536f24..aefbe63606a 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 9220828014f..b0c56003957 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`. |
