Prevent multiple incorrect case diagnostics in functions

This commit is contained in:
unexge 2020-12-23 22:18:31 +03:00
parent 3d5d21b602
commit bfae2634b4
2 changed files with 16 additions and 3 deletions

View File

@ -374,8 +374,6 @@ pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
let crate_def_map = db.crate_def_map(self.id.krate);
crate_def_map.add_diagnostics(db.upcast(), self.id.local_id, sink);
for decl in self.declarations(db) {
decl.diagnostics(db, sink);
match decl {
crate::ModuleDef::Function(f) => f.diagnostics(db, sink),
crate::ModuleDef::Module(m) => {
@ -384,7 +382,9 @@ pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
m.diagnostics(db, sink)
}
}
_ => (),
_ => {
decl.diagnostics(db, sink);
}
}
}

View File

@ -895,4 +895,17 @@ pub fn some_fn() -> TestStruct {
"#,
);
}
#[test]
fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() {
let input = r#"fn FOO<|>() {}"#;
let expected = r#"fn foo() {}"#;
let (analysis, file_position) = fixture::position(input);
let diagnostics =
analysis.diagnostics(&DiagnosticsConfig::default(), file_position.file_id).unwrap();
assert_eq!(diagnostics.len(), 1);
check_fixes(input, expected);
}
}