From dec207f56a7b16075f68dcb89138d93a7eecdf43 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 19:27:14 +0300 Subject: minor: simplify --- crates/ide/src/diagnostics.rs | 21 +++------------------ crates/ide/src/diagnostics/field_shorthand.rs | 10 +++++----- crates/ide/src/diagnostics/fixes/change_case.rs | 4 ++-- crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs | 6 +++--- crates/ide/src/diagnostics/macro_error.rs | 6 ++---- crates/ide/src/diagnostics/missing_fields.rs | 6 +++--- 6 files changed, 18 insertions(+), 35 deletions(-) diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index fb956d5ee..aeccf1164 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -416,21 +416,6 @@ mod tests { assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {:?}", diagnostic); } - /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics - /// apply to the file containing the cursor. - pub(crate) fn check_no_diagnostics(ra_fixture: &str) { - let (analysis, files) = fixture::files(ra_fixture); - let diagnostics = files - .into_iter() - .flat_map(|file_id| { - analysis - .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id) - .unwrap() - }) - .collect::>(); - assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); - } - pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) { let (analysis, file_id) = fixture::file(ra_fixture); let diagnostics = analysis @@ -496,7 +481,7 @@ pub struct Foo { pub a: i32, pub b: i32 } #[test] fn test_check_unnecessary_braces_in_use_statement() { - check_no_diagnostics( + check_diagnostics( r#" use a; use a::{c, d::e}; @@ -509,7 +494,7 @@ mod a { } "#, ); - check_no_diagnostics( + check_diagnostics( r#" use a; use a::{ @@ -719,7 +704,7 @@ $0 #[test] fn unlinked_file_with_cfg_on() { - check_no_diagnostics( + check_diagnostics( r#" //- /main.rs #[cfg(not(never))] diff --git a/crates/ide/src/diagnostics/field_shorthand.rs b/crates/ide/src/diagnostics/field_shorthand.rs index 01bd2dba6..e885a398e 100644 --- a/crates/ide/src/diagnostics/field_shorthand.rs +++ b/crates/ide/src/diagnostics/field_shorthand.rs @@ -98,17 +98,17 @@ fn check_pat_field_shorthand( #[cfg(test)] mod tests { - use crate::diagnostics::tests::{check_fix, check_no_diagnostics}; + use crate::diagnostics::tests::{check_diagnostics, check_fix}; #[test] fn test_check_expr_field_shorthand() { - check_no_diagnostics( + check_diagnostics( r#" struct A { a: &'static str } fn main() { A { a: "hello" } } "#, ); - check_no_diagnostics( + check_diagnostics( r#" struct A(usize); fn main() { A { 0: 0 } } @@ -154,13 +154,13 @@ fn main() { #[test] fn test_check_pat_field_shorthand() { - check_no_diagnostics( + check_diagnostics( r#" struct A { a: &'static str } fn f(a: A) { let A { a: hello } = a; } "#, ); - check_no_diagnostics( + check_diagnostics( r#" struct A(usize); fn f(a: A) { let A { 0: 0 } = a; } diff --git a/crates/ide/src/diagnostics/fixes/change_case.rs b/crates/ide/src/diagnostics/fixes/change_case.rs index 42be3375f..db1a37cd6 100644 --- a/crates/ide/src/diagnostics/fixes/change_case.rs +++ b/crates/ide/src/diagnostics/fixes/change_case.rs @@ -35,7 +35,7 @@ impl DiagnosticWithFixes for IncorrectCase { #[cfg(test)] mod change_case { use crate::{ - diagnostics::tests::{check_fix, check_no_diagnostics}, + diagnostics::tests::{check_diagnostics, check_fix}, fixture, AssistResolveStrategy, DiagnosticsConfig, }; @@ -102,7 +102,7 @@ fn some_fn() { #[test] fn test_uppercase_const_no_diagnostics() { - check_no_diagnostics( + check_diagnostics( r#" fn foo() { const ANOTHER_ITEM$0: &str = "some_item"; diff --git a/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs b/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs index 715a403b9..dcb21e037 100644 --- a/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs +++ b/crates/ide/src/diagnostics/fixes/wrap_tail_expr.rs @@ -25,7 +25,7 @@ impl DiagnosticWithFixes for MissingOkOrSomeInTailExpr { #[cfg(test)] mod tests { - use crate::diagnostics::tests::{check_fix, check_no_diagnostics}; + use crate::diagnostics::tests::{check_diagnostics, check_fix}; #[test] fn test_wrap_return_type_option() { @@ -169,7 +169,7 @@ fn div(x: i32, y: i32) -> MyResult { #[test] fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() { - check_no_diagnostics( + check_diagnostics( r#" //- /main.rs crate:main deps:core use core::result::Result::{self, Ok, Err}; @@ -189,7 +189,7 @@ pub mod option { #[test] fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() { - check_no_diagnostics( + check_diagnostics( r#" //- /main.rs crate:main deps:core use core::result::Result::{self, Ok, Err}; diff --git a/crates/ide/src/diagnostics/macro_error.rs b/crates/ide/src/diagnostics/macro_error.rs index d76a3a094..5f97f190d 100644 --- a/crates/ide/src/diagnostics/macro_error.rs +++ b/crates/ide/src/diagnostics/macro_error.rs @@ -15,9 +15,7 @@ pub(super) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) -> #[cfg(test)] mod tests { use crate::{ - diagnostics::tests::{ - check_diagnostics, check_diagnostics_with_config, check_no_diagnostics, - }, + diagnostics::tests::{check_diagnostics, check_diagnostics_with_config}, DiagnosticsConfig, }; @@ -77,7 +75,7 @@ macro_rules! concat { () => {} } fn register_attr_and_tool() { cov_mark::check!(register_attr); cov_mark::check!(register_tool); - check_no_diagnostics( + check_diagnostics( r#" #![register_tool(tool)] #![register_attr(attr)] diff --git a/crates/ide/src/diagnostics/missing_fields.rs b/crates/ide/src/diagnostics/missing_fields.rs index 66575f713..95cd64956 100644 --- a/crates/ide/src/diagnostics/missing_fields.rs +++ b/crates/ide/src/diagnostics/missing_fields.rs @@ -77,7 +77,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option