Skip to content

Commit d124476

Browse files
authored
Unrolled build for rust-lang#140090
Rollup merge of rust-lang#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 rust-lang#140089. cc `@theemathas`
2 parents 7188f45 + 8307f97 commit d124476

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

compiler/rustc_lint/src/nonstandard_style.rs

+10
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
422422
}
423423
}
424424

425+
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_, hir::AmbigArg>) {
426+
if let hir::TyKind::BareFn(hir::BareFnTy { param_idents, .. }) = &ty.kind {
427+
for param_ident in *param_idents {
428+
if let Some(param_ident) = param_ident {
429+
self.check_snake_case(cx, "variable", param_ident);
430+
}
431+
}
432+
}
433+
}
434+
425435
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &hir::TraitItem<'_>) {
426436
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(param_idents)) = item.kind {
427437
self.check_snake_case(cx, "trait method", &item.ident);

tests/ui/lint/non-snake-case/lint-uppercase-variables.rs

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ fn main() {
3535
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
3636
//~^^^ WARN unused variable: `Foo`
3737

38+
let _: fn(CamelCase: i32);
39+
//~^ ERROR variable `CamelCase` should have a snake case name
40+
3841
test(1);
3942

4043
let _ = Something { X: 0 };

tests/ui/lint/non-snake-case/lint-uppercase-variables.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ error: variable `Foo` should have a snake case name
8585
LL | fn in_param(Foo: foo::Foo) {}
8686
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`
8787

88-
error: aborting due to 9 previous errors; 3 warnings emitted
88+
error: variable `CamelCase` should have a snake case name
89+
--> $DIR/lint-uppercase-variables.rs:38:15
90+
|
91+
LL | let _: fn(CamelCase: i32);
92+
| ^^^^^^^^^ help: convert the identifier to snake case: `camel_case`
93+
94+
error: aborting due to 10 previous errors; 3 warnings emitted
8995

9096
For more information about this error, try `rustc --explain E0170`.

0 commit comments

Comments
 (0)