fix conflicting "unnecessary else" and "trailing return" diagnostics tests
This commit is contained in:
parent
a250c2dde0
commit
602acfcb70
@ -67,9 +67,9 @@ diagnostics![
|
|||||||
NoSuchField,
|
NoSuchField,
|
||||||
PrivateAssocItem,
|
PrivateAssocItem,
|
||||||
PrivateField,
|
PrivateField,
|
||||||
ReplaceFilterMapNextWithFindMap,
|
|
||||||
RemoveTrailingReturn,
|
RemoveTrailingReturn,
|
||||||
RemoveUnnecessaryElse,
|
RemoveUnnecessaryElse,
|
||||||
|
ReplaceFilterMapNextWithFindMap,
|
||||||
TraitImplIncorrectSafety,
|
TraitImplIncorrectSafety,
|
||||||
TraitImplMissingAssocItems,
|
TraitImplMissingAssocItems,
|
||||||
TraitImplOrphan,
|
TraitImplOrphan,
|
||||||
|
@ -54,7 +54,9 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &RemoveTrailingReturn) -> Option<Vec<A
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_diagnostics, check_fix};
|
use crate::tests::{
|
||||||
|
check_diagnostics, check_diagnostics_with_disabled, check_fix, check_fix_with_disabled,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_trailing_return() {
|
fn remove_trailing_return() {
|
||||||
@ -127,7 +129,7 @@ fn foo() -> u8 {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_trailing_return_in_if() {
|
fn remove_trailing_return_in_if() {
|
||||||
check_diagnostics(
|
check_diagnostics_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn foo(x: usize) -> u8 {
|
fn foo(x: usize) -> u8 {
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
@ -138,6 +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_string()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +290,7 @@ fn foo() -> u8 {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn replace_in_if() {
|
fn replace_in_if() {
|
||||||
check_fix(
|
check_fix_with_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn foo(x: usize) -> u8 {
|
fn foo(x: usize) -> u8 {
|
||||||
if x > 0 {
|
if x > 0 {
|
||||||
@ -306,6 +309,7 @@ fn foo(x: usize) -> u8 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
std::iter::once("remove-unnecessary-else".to_string()),
|
||||||
);
|
);
|
||||||
check_fix(
|
check_fix(
|
||||||
r#"
|
r#"
|
||||||
|
@ -87,11 +87,15 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &RemoveUnnecessaryElse) -> Option<Vec<
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_diagnostics, 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_string()));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return() {
|
fn remove_unnecessary_else_for_return() {
|
||||||
check_diagnostics(
|
check_diagnostics_with_needless_return_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -126,7 +130,7 @@ fn test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return2() {
|
fn remove_unnecessary_else_for_return2() {
|
||||||
check_diagnostics(
|
check_diagnostics_with_needless_return_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -169,7 +173,7 @@ fn test() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn remove_unnecessary_else_for_return_in_child_if_expr() {
|
fn remove_unnecessary_else_for_return_in_child_if_expr() {
|
||||||
check_diagnostics(
|
check_diagnostics_with_needless_return_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
@ -371,7 +375,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(
|
check_diagnostics_with_needless_return_disabled(
|
||||||
r#"
|
r#"
|
||||||
fn test() {
|
fn test() {
|
||||||
if foo {
|
if foo {
|
||||||
|
@ -34,13 +34,35 @@ pub(crate) fn check_fixes(ra_fixture_before: &str, ra_fixtures_after: Vec<&str>)
|
|||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
|
fn check_nth_fix(nth: usize, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||||
|
let mut config = DiagnosticsConfig::test_sample();
|
||||||
|
config.expr_fill_default = ExprFillDefaultMode::Default;
|
||||||
|
check_nth_fix_with_config(config, nth, ra_fixture_before, ra_fixture_after)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
pub(crate) fn check_fix_with_disabled(
|
||||||
|
ra_fixture_before: &str,
|
||||||
|
ra_fixture_after: &str,
|
||||||
|
disabled: impl Iterator<Item = String>,
|
||||||
|
) {
|
||||||
|
let mut config = DiagnosticsConfig::test_sample();
|
||||||
|
config.expr_fill_default = ExprFillDefaultMode::Default;
|
||||||
|
config.disabled.extend(disabled);
|
||||||
|
check_nth_fix_with_config(config, 0, ra_fixture_before, ra_fixture_after)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
|
fn check_nth_fix_with_config(
|
||||||
|
config: DiagnosticsConfig,
|
||||||
|
nth: usize,
|
||||||
|
ra_fixture_before: &str,
|
||||||
|
ra_fixture_after: &str,
|
||||||
|
) {
|
||||||
let after = trim_indent(ra_fixture_after);
|
let after = trim_indent(ra_fixture_after);
|
||||||
|
|
||||||
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
|
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
|
||||||
let mut conf = DiagnosticsConfig::test_sample();
|
|
||||||
conf.expr_fill_default = ExprFillDefaultMode::Default;
|
|
||||||
let diagnostic =
|
let diagnostic =
|
||||||
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id)
|
super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_position.file_id)
|
||||||
.pop()
|
.pop()
|
||||||
.expect("no diagnostics");
|
.expect("no diagnostics");
|
||||||
let fix = &diagnostic
|
let fix = &diagnostic
|
||||||
|
Loading…
x
Reference in New Issue
Block a user