This commit is contained in:
Lukas Wirth 2024-02-19 13:53:29 +01:00
parent a492d9d164
commit 1e448f84c3
2 changed files with 7 additions and 4 deletions

View file

@ -179,7 +179,7 @@ fn test() {
#[test] #[test]
fn remove_unnecessary_else_for_return3() { fn remove_unnecessary_else_for_return3() {
check_diagnostics_with_needless_return_disabled( check_diagnostics_with_disabled(
r#" r#"
fn test(a: bool) -> i32 { fn test(a: bool) -> i32 {
if a { if a {
@ -190,6 +190,7 @@ fn test(a: bool) -> i32 {
} }
} }
"#, "#,
&["needless_return", "E0425"],
); );
check_fix( check_fix(
r#" r#"
@ -473,7 +474,7 @@ fn test() {
#[test] #[test]
fn no_diagnostic_if_not_expr_stmt() { fn no_diagnostic_if_not_expr_stmt() {
check_diagnostics_with_needless_return_disabled( check_diagnostics_with_disabled(
r#" r#"
fn test1() { fn test1() {
let _x = if a { let _x = if a {
@ -495,13 +496,15 @@ fn test2() {
}; };
} }
"#, "#,
&["needless_return", "E0425"],
); );
check_diagnostics( check_diagnostics_with_disabled(
r#" r#"
fn test3() -> u8 { fn test3() -> u8 {
foo(if a { return 1 } else { 0 }) foo(if a { return 1 } else { 0 })
} }
"#, "#,
&["E0425"],
); );
} }
} }

View file

@ -200,7 +200,7 @@ pub(crate) fn check_diagnostics(ra_fixture: &str) {
#[track_caller] #[track_caller]
pub(crate) fn check_diagnostics_with_disabled(ra_fixture: &str, disabled: &[&str]) { pub(crate) fn check_diagnostics_with_disabled(ra_fixture: &str, disabled: &[&str]) {
let mut config = DiagnosticsConfig::test_sample(); let mut config = DiagnosticsConfig::test_sample();
config.disabled.extend(disabled.into_iter().map(|&s| s.to_owned())); config.disabled.extend(disabled.iter().map(|&s| s.to_owned()));
check_diagnostics_with_config(config, ra_fixture) check_diagnostics_with_config(config, ra_fixture)
} }