mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
internal: make check_diagnostics_with_disabled more ergonomic
This commit is contained in:
parent
e6b96dba56
commit
d818b531c9
6 changed files with 15 additions and 18 deletions
|
@ -512,7 +512,7 @@ impl BAD_TRAIT for () {
|
|||
fn BadFunction() {}
|
||||
}
|
||||
"#,
|
||||
std::iter::once("unused_variables".to_owned()),
|
||||
&["unused_variables"],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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#"
|
||||
|
@ -463,7 +463,7 @@ fn main(b: bool) {
|
|||
&mut x;
|
||||
}
|
||||
"#,
|
||||
std::iter::once("remove-unnecessary-else".to_owned()),
|
||||
&["remove-unnecessary-else"],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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"],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -114,6 +110,7 @@ fn test() {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
&["needless_return"],
|
||||
);
|
||||
check_fix(
|
||||
r#"
|
||||
|
@ -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 {
|
||||
|
@ -151,6 +148,7 @@ fn test() {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
&["needless_return"],
|
||||
);
|
||||
check_fix(
|
||||
r#"
|
||||
|
@ -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 {
|
||||
|
@ -229,6 +227,7 @@ fn test() {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
&["needless_return"],
|
||||
);
|
||||
check_fix(
|
||||
r#"
|
||||
|
@ -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 {
|
||||
|
@ -463,6 +462,7 @@ fn test() {
|
|||
}
|
||||
}
|
||||
"#,
|
||||
&["needless_return"],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -730,7 +730,7 @@ fn f() -> i32 {
|
|||
}
|
||||
fn g() { return; }
|
||||
"#,
|
||||
std::iter::once("needless_return".to_owned()),
|
||||
&["needless_return"],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue