mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
internal: make check_diagnostics_with_disabled more ergonomic
This commit is contained in:
parent
e6b96dba56
commit
d818b531c9
@ -512,7 +512,7 @@ impl BAD_TRAIT for () {
|
|||||||
fn BadFunction() {}
|
fn BadFunction() {}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
std::iter::once("unused_variables".to_owned()),
|
&["unused_variables"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ fn main(b: bool) {
|
|||||||
&mut x;
|
&mut x;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
std::iter::once("remove-unnecessary-else".to_owned()),
|
&["remove-unnecessary-else"],
|
||||||
);
|
);
|
||||||
check_diagnostics_with_disabled(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
@ -463,7 +463,7 @@ fn main(b: bool) {
|
|||||||
&mut x;
|
&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>
|
} //^^^^^^^^^ 💡 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 {
|
mod tests {
|
||||||
use crate::tests::{check_diagnostics, check_diagnostics_with_disabled, check_fix};
|
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]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return() {
|
fn remove_unnecessary_else_for_return() {
|
||||||
check_diagnostics_with_needless_return_disabled(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -114,6 +110,7 @@ fn test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
&["needless_return"],
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
r#"
|
r#"
|
||||||
@ -138,7 +135,7 @@ fn test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return2() {
|
fn remove_unnecessary_else_for_return2() {
|
||||||
check_diagnostics_with_needless_return_disabled(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -151,6 +148,7 @@ fn test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
&["needless_return"],
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
r#"
|
r#"
|
||||||
@ -216,7 +214,7 @@ fn test(a: bool) -> i32 {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return_in_child_if_expr() {
|
fn remove_unnecessary_else_for_return_in_child_if_expr() {
|
||||||
check_diagnostics_with_needless_return_disabled(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -229,6 +227,7 @@ fn test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
&["needless_return"],
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
r#"
|
r#"
|
||||||
@ -453,7 +452,7 @@ fn test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_diagnostic_if_no_divergence_in_else_branch() {
|
fn no_diagnostic_if_no_divergence_in_else_branch() {
|
||||||
check_diagnostics_with_needless_return_disabled(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -463,6 +462,7 @@ fn test() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
&["needless_return"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,7 +730,7 @@ fn f() -> i32 {
|
|||||||
}
|
}
|
||||||
fn g() { return; }
|
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]
|
#[track_caller]
|
||||||
pub(crate) fn check_diagnostics_with_disabled(
|
pub(crate) fn check_diagnostics_with_disabled(ra_fixture: &str, disabled: &[&str]) {
|
||||||
ra_fixture: &str,
|
|
||||||
disabled: impl Iterator<Item = String>,
|
|
||||||
) {
|
|
||||||
let mut config = DiagnosticsConfig::test_sample();
|
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)
|
check_diagnostics_with_config(config, ra_fixture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user