Skip to content

Commit

Permalink
internal: make check_diagnostics_with_disabled more ergonomic
Browse files Browse the repository at this point in the history
  • Loading branch information
rosefromthedead authored and Veykril committed Feb 19, 2024
1 parent e6b96db commit d818b53
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/ide-diagnostics/src/handlers/incorrect_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl BAD_TRAIT for () {
fn BadFunction() {}
}
"#,
std::iter::once("unused_variables".to_owned()),
&["unused_variables"],
);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/ide-diagnostics/src/handlers/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ fn main(b: bool) {
&mut x;
}
"#,
std::iter::once("remove-unnecessary-else".to_owned()),
&["remove-unnecessary-else"],
);
check_diagnostics_with_disabled(
r#"
Expand All @@ -463,7 +463,7 @@ fn main(b: bool) {
&mut x;
}
"#,
std::iter::once("remove-unnecessary-else".to_owned()),
&["remove-unnecessary-else"],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn foo(x: usize) -> u8 {
} //^^^^^^^^^ 💡 weak: replace return <expr>; with <expr>
}
"#,
std::iter::once("remove-unnecessary-else".to_owned()),
&["remove-unnecessary-else"],
);
}

Expand Down
16 changes: 8 additions & 8 deletions crates/ide-diagnostics/src/handlers/remove_unnecessary_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &RemoveUnnecessaryElse) -> Option<Vec<
mod tests {
use crate::tests::{check_diagnostics, check_diagnostics_with_disabled, check_fix};

fn check_diagnostics_with_needless_return_disabled(ra_fixture: &str) {
check_diagnostics_with_disabled(ra_fixture, std::iter::once("needless_return".to_owned()));
}

#[test]
fn remove_unnecessary_else_for_return() {
check_diagnostics_with_needless_return_disabled(
check_diagnostics_with_disabled(
r#"
fn test() {
if foo {
Expand All @@ -114,6 +110,7 @@ fn test() {
}
}
"#,
&["needless_return"],
);
check_fix(
r#"
Expand All @@ -138,7 +135,7 @@ fn test() {

#[test]
fn remove_unnecessary_else_for_return2() {
check_diagnostics_with_needless_return_disabled(
check_diagnostics_with_disabled(
r#"
fn test() {
if foo {
Expand All @@ -151,6 +148,7 @@ fn test() {
}
}
"#,
&["needless_return"],
);
check_fix(
r#"
Expand Down Expand Up @@ -216,7 +214,7 @@ fn test(a: bool) -> i32 {

#[test]
fn remove_unnecessary_else_for_return_in_child_if_expr() {
check_diagnostics_with_needless_return_disabled(
check_diagnostics_with_disabled(
r#"
fn test() {
if foo {
Expand All @@ -229,6 +227,7 @@ fn test() {
}
}
"#,
&["needless_return"],
);
check_fix(
r#"
Expand Down Expand Up @@ -453,7 +452,7 @@ fn test() {

#[test]
fn no_diagnostic_if_no_divergence_in_else_branch() {
check_diagnostics_with_needless_return_disabled(
check_diagnostics_with_disabled(
r#"
fn test() {
if foo {
Expand All @@ -463,6 +462,7 @@ fn test() {
}
}
"#,
&["needless_return"],
);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ide-diagnostics/src/handlers/type_mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ fn f() -> i32 {
}
fn g() { return; }
"#,
std::iter::once("needless_return".to_owned()),
&["needless_return"],
);
}

Expand Down
7 changes: 2 additions & 5 deletions crates/ide-diagnostics/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,9 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
}

#[track_caller]
pub(crate) fn check_diagnostics_with_disabled(
ra_fixture: &str,
disabled: impl Iterator<Item = String>,
) {
pub(crate) fn check_diagnostics_with_disabled(ra_fixture: &str, disabled: &[&str]) {
let mut config = DiagnosticsConfig::test_sample();
config.disabled.extend(disabled);
config.disabled.extend(disabled.into_iter().map(|&s| s.to_owned()));
check_diagnostics_with_config(config, ra_fixture)
}

Expand Down

0 comments on commit d818b53

Please sign in to comment.