Skip to content

Check bare function idents for non snake-case name #140090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_lint/src/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/lint/non-snake-case/lint-uppercase-variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Loading