Skip to content

Commit b45ee82

Browse files
committed
incorrect case diagnostics for param names of trait impl assoc functions
1 parent 33b3b6d commit b45ee82

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

crates/hir-ty/src/diagnostics/decl_check.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -316,31 +316,19 @@ impl<'a> DeclValidator<'a> {
316316
/// Check incorrect names for patterns inside the function body.
317317
/// This includes function parameters except for trait implementation associated functions.
318318
fn validate_func_body(&mut self, func: FunctionId) {
319-
// Check whether function is an associated item of a trait implementation
320-
let container = func.lookup(self.db.upcast()).container;
321-
let is_trait_impl_assoc_fn = self.is_trait_impl_container(container);
322-
323319
let body = self.db.body(func.into());
324320
let mut pats_replacements = body
325321
.pats
326322
.iter()
327323
.filter_map(|(pat_id, pat)| match pat {
328324
Pat::Bind { id, .. } => {
329-
// Filter out parameters for trait implementation associated functions.
330-
if is_trait_impl_assoc_fn
331-
&& body.params.iter().any(|param_id| *param_id == pat_id)
332-
{
333-
cov_mark::hit!(trait_impl_assoc_func_param_incorrect_case_ignored);
334-
None
335-
} else {
336-
let bind_name = &body.bindings[*id].name;
337-
let replacement = Replacement {
338-
current_name: bind_name.clone(),
339-
suggested_text: to_lower_snake_case(&bind_name.to_smol_str())?,
340-
expected_case: CaseType::LowerSnakeCase,
341-
};
342-
Some((pat_id, replacement))
343-
}
325+
let bind_name = &body.bindings[*id].name;
326+
let replacement = Replacement {
327+
current_name: bind_name.clone(),
328+
suggested_text: to_lower_snake_case(&bind_name.to_smol_str())?,
329+
expected_case: CaseType::LowerSnakeCase,
330+
};
331+
Some((pat_id, replacement))
344332
}
345333
_ => None,
346334
})

crates/ide-diagnostics/src/handlers/incorrect_case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ trait BAD_TRAIT {
486486
cov_mark::check!(trait_impl_assoc_const_incorrect_case_ignored);
487487
cov_mark::check!(trait_impl_assoc_type_incorrect_case_ignored);
488488
cov_mark::check_count!(trait_impl_assoc_func_name_incorrect_case_ignored, 2);
489-
cov_mark::check!(trait_impl_assoc_func_param_incorrect_case_ignored);
490489
check_diagnostics_with_disabled(
491490
r#"
492491
trait BAD_TRAIT {
@@ -506,6 +505,7 @@ impl BAD_TRAIT for () {
506505
const bad_const: u8 = 0;
507506
type BAD_TYPE = ();
508507
fn BAD_FUNCTION(BAD_PARAM: u8) {
508+
// ^^^^^^^^^ 💡 warn: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param`
509509
let BAD_VAR = 0;
510510
// ^^^^^^^ 💡 warn: Variable `BAD_VAR` should have snake_case name, e.g. `bad_var`
511511
}

0 commit comments

Comments
 (0)