From bfae2634b496caa54f38f4c22d285c5fc1dad190 Mon Sep 17 00:00:00 2001 From: unexge Date: Wed, 23 Dec 2020 22:18:31 +0300 Subject: 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(-) (limited to 'crates') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 1d7e5ddd7..6d17d546a 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -374,8 +374,6 @@ impl Module { 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 @@ impl Module { m.diagnostics(db, sink) } } - _ => (), + _ => { + decl.diagnostics(db, sink); + } } } diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 3ad30f0c9..b2714cb69 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -895,4 +895,17 @@ impl 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); + } } -- cgit v1.2.3