mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
incorrect case diagnostics for param names of trait impl assoc functions
This commit is contained in:
parent
33b3b6dbf9
commit
b45ee82811
2 changed files with 8 additions and 20 deletions
|
@ -316,31 +316,19 @@ impl<'a> DeclValidator<'a> {
|
|||
/// Check incorrect names for patterns inside the function body.
|
||||
/// This includes function parameters except for trait implementation associated functions.
|
||||
fn validate_func_body(&mut self, func: FunctionId) {
|
||||
// Check whether function is an associated item of a trait implementation
|
||||
let container = func.lookup(self.db.upcast()).container;
|
||||
let is_trait_impl_assoc_fn = self.is_trait_impl_container(container);
|
||||
|
||||
let body = self.db.body(func.into());
|
||||
let mut pats_replacements = body
|
||||
.pats
|
||||
.iter()
|
||||
.filter_map(|(pat_id, pat)| match pat {
|
||||
Pat::Bind { id, .. } => {
|
||||
// Filter out parameters for trait implementation associated functions.
|
||||
if is_trait_impl_assoc_fn
|
||||
&& body.params.iter().any(|param_id| *param_id == pat_id)
|
||||
{
|
||||
cov_mark::hit!(trait_impl_assoc_func_param_incorrect_case_ignored);
|
||||
None
|
||||
} else {
|
||||
let bind_name = &body.bindings[*id].name;
|
||||
let replacement = Replacement {
|
||||
current_name: bind_name.clone(),
|
||||
suggested_text: to_lower_snake_case(&bind_name.to_smol_str())?,
|
||||
expected_case: CaseType::LowerSnakeCase,
|
||||
};
|
||||
Some((pat_id, replacement))
|
||||
}
|
||||
let bind_name = &body.bindings[*id].name;
|
||||
let replacement = Replacement {
|
||||
current_name: bind_name.clone(),
|
||||
suggested_text: to_lower_snake_case(&bind_name.to_smol_str())?,
|
||||
expected_case: CaseType::LowerSnakeCase,
|
||||
};
|
||||
Some((pat_id, replacement))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
|
|
|
@ -486,7 +486,6 @@ trait BAD_TRAIT {
|
|||
cov_mark::check!(trait_impl_assoc_const_incorrect_case_ignored);
|
||||
cov_mark::check!(trait_impl_assoc_type_incorrect_case_ignored);
|
||||
cov_mark::check_count!(trait_impl_assoc_func_name_incorrect_case_ignored, 2);
|
||||
cov_mark::check!(trait_impl_assoc_func_param_incorrect_case_ignored);
|
||||
check_diagnostics_with_disabled(
|
||||
r#"
|
||||
trait BAD_TRAIT {
|
||||
|
@ -506,6 +505,7 @@ impl BAD_TRAIT for () {
|
|||
const bad_const: u8 = 0;
|
||||
type BAD_TYPE = ();
|
||||
fn BAD_FUNCTION(BAD_PARAM: u8) {
|
||||
// ^^^^^^^^^ 💡 warn: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param`
|
||||
let BAD_VAR = 0;
|
||||
// ^^^^^^^ 💡 warn: Variable `BAD_VAR` should have snake_case name, e.g. `bad_var`
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue