Skip to content

Commit d76669f

Browse files
committed
fix(hir): missing validators in test diagnostics
1 parent 425ca37 commit d76669f

File tree

2 files changed

+11
-32
lines changed

2 files changed

+11
-32
lines changed

crates/mun_hir/src/expr/validator/tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn test_uninitialized_access() {
66
insta::assert_snapshot!(
77
diagnostics(r#"
88
fn foo() {
9-
let a:int;
9+
let a:i64;
1010
let b = a + 3;
1111
}
1212
"#), @"38..39: use of possibly-uninitialized variable"
@@ -18,31 +18,31 @@ fn test_uninitialized_access_if() {
1818
insta::assert_snapshot!(diagnostics(
1919
r#"
2020
fn foo() {
21-
let a:int;
21+
let a:i64;
2222
if true { a = 3; } else { a = 4; }
2323
let b = a + 4; // correct, `a` is initialized either way
2424
}
2525
2626
fn bar() {
27-
let a:int;
27+
let a:i64;
2828
if true { a = 3; }
2929
let b = a + 4; // `a` is possibly-unitialized
3030
}
3131
3232
fn baz() {
33-
let a:int;
33+
let a:i64;
3434
if true { return } else { a = 4 };
3535
let b = a + 4; // correct, `a` is initialized either way
3636
}
3737
3838
fn foz() {
39-
let a:int;
39+
let a:i64;
4040
if true { a = 4 } else { return };
4141
let b = a + 4; // correct, `a` is initialized either way
4242
}
4343
4444
fn boz() {
45-
let a:int;
45+
let a:i64;
4646
return;
4747
let b = a + 4; // `a` is not initialized but this is dead code anyway
4848
}
@@ -54,8 +54,8 @@ fn test_uninitialized_access_if() {
5454
fn test_uninitialized_access_while() {
5555
insta::assert_snapshot!(diagnostics(
5656
r#"
57-
fn foo(b:int) {
58-
let a:int;
57+
fn foo(b:i64) {
58+
let a:i64;
5959
while b < 4 { b += 1; a = b; a += 1; }
6060
let c = a + 4; // `a` is possibly-unitialized
6161
}

crates/mun_hir/src/utils.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
1212
#[cfg(test)]
1313
pub mod tests {
1414
use crate::{
15-
code_model::r#struct::validator::StructValidator,
16-
diagnostics::DiagnosticSink,
17-
expr::validator::{ExprValidator, TypeAliasValidator},
18-
mock::MockDatabase,
19-
with_fixture::WithFixture,
20-
FileId, ModuleDef, Package,
15+
diagnostics::DiagnosticSink, mock::MockDatabase, with_fixture::WithFixture, Package,
2116
};
2217

2318
pub fn diagnostics(content: &str) -> String {
@@ -29,24 +24,8 @@ pub mod tests {
2924
diags.push(format!("{:?}: {}", diag.highlight_range(), diag.message()));
3025
});
3126

32-
for item in Package::all(&db)
33-
.iter()
34-
.flat_map(|pkg| pkg.modules(&db))
35-
.flat_map(|module| module.declarations(&db))
36-
{
37-
match item {
38-
ModuleDef::Function(item) => {
39-
ExprValidator::new(item, &db).validate_body(&mut diag_sink);
40-
}
41-
ModuleDef::TypeAlias(item) => {
42-
TypeAliasValidator::new(item, &db)
43-
.validate_target_type_existence(&mut diag_sink);
44-
}
45-
ModuleDef::Struct(item) => {
46-
StructValidator::new(item, &db, FileId(0)).validate_privacy(&mut diag_sink);
47-
}
48-
_ => {}
49-
}
27+
for module in Package::all(&db).iter().flat_map(|pkg| pkg.modules(&db)) {
28+
module.diagnostics(&db, &mut diag_sink);
5029
}
5130

5231
drop(diag_sink);

0 commit comments

Comments
 (0)