7022: Prevent multiple incorrect case diagnostics in functions r=lnicola a=unexge

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6970

Co-authored-by: unexge <unexge@gmail.com>
This commit is contained in:
bors[bot] 2020-12-23 19:44:27 +00:00 committed by GitHub
commit 01a3fd9600
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -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);
}
}
}

View file

@ -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);
}
}