From bfae2634b496caa54f38f4c22d285c5fc1dad190 Mon Sep 17 00:00:00 2001 From: unexge Date: Wed, 23 Dec 2020 22:18:31 +0300 Subject: [PATCH] Prevent multiple incorrect case diagnostics in functions --- crates/hir/src/code_model.rs | 6 +++--- crates/ide/src/diagnostics.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 1d7e5ddd7f6..6d17d546acf 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -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); + } } } diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 3ad30f0c9e2..b2714cb6915 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -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); + } }