Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hir): missing validators in test diagnostics #527

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/mun_hir/src/expr/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn test_uninitialized_access() {
insta::assert_snapshot!(
diagnostics(r#"
fn foo() {
let a:int;
let a:i64;
let b = a + 3;
}
"#), @"38..39: use of possibly-uninitialized variable"
Expand All @@ -18,31 +18,31 @@ fn test_uninitialized_access_if() {
insta::assert_snapshot!(diagnostics(
r#"
fn foo() {
let a:int;
let a:i64;
if true { a = 3; } else { a = 4; }
let b = a + 4; // correct, `a` is initialized either way
}

fn bar() {
let a:int;
let a:i64;
if true { a = 3; }
let b = a + 4; // `a` is possibly-unitialized
}

fn baz() {
let a:int;
let a:i64;
if true { return } else { a = 4 };
let b = a + 4; // correct, `a` is initialized either way
}

fn foz() {
let a:int;
let a:i64;
if true { a = 4 } else { return };
let b = a + 4; // correct, `a` is initialized either way
}

fn boz() {
let a:int;
let a:i64;
return;
let b = a + 4; // `a` is not initialized but this is dead code anyway
}
Expand All @@ -54,8 +54,8 @@ fn test_uninitialized_access_if() {
fn test_uninitialized_access_while() {
insta::assert_snapshot!(diagnostics(
r#"
fn foo(b:int) {
let a:int;
fn foo(b:i64) {
let a:i64;
while b < 4 { b += 1; a = b; a += 1; }
let c = a + 4; // `a` is possibly-unitialized
}
Expand Down
27 changes: 3 additions & 24 deletions crates/mun_hir/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
#[cfg(test)]
pub mod tests {
use crate::{
code_model::r#struct::validator::StructValidator,
diagnostics::DiagnosticSink,
expr::validator::{ExprValidator, TypeAliasValidator},
mock::MockDatabase,
with_fixture::WithFixture,
FileId, ModuleDef, Package,
diagnostics::DiagnosticSink, mock::MockDatabase, with_fixture::WithFixture, Package,
};

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

for item in Package::all(&db)
.iter()
.flat_map(|pkg| pkg.modules(&db))
.flat_map(|module| module.declarations(&db))
{
match item {
ModuleDef::Function(item) => {
ExprValidator::new(item, &db).validate_body(&mut diag_sink);
}
ModuleDef::TypeAlias(item) => {
TypeAliasValidator::new(item, &db)
.validate_target_type_existence(&mut diag_sink);
}
ModuleDef::Struct(item) => {
StructValidator::new(item, &db, FileId(0)).validate_privacy(&mut diag_sink);
}
_ => {}
}
for module in Package::all(&db).iter().flat_map(|pkg| pkg.modules(&db)) {
module.diagnostics(&db, &mut diag_sink);
}

drop(diag_sink);
Expand Down