mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
minor: simplify
This commit is contained in:
parent
a1940d8c75
commit
dec207f56a
@ -416,21 +416,6 @@ mod tests {
|
|||||||
assert!(diagnostic.fixes.is_none(), "got a fix when none was expected: {:?}", diagnostic);
|
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::<Vec<_>>();
|
|
||||||
assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) {
|
pub(crate) fn check_expect(ra_fixture: &str, expect: Expect) {
|
||||||
let (analysis, file_id) = fixture::file(ra_fixture);
|
let (analysis, file_id) = fixture::file(ra_fixture);
|
||||||
let diagnostics = analysis
|
let diagnostics = analysis
|
||||||
@ -496,7 +481,7 @@ pub struct Foo { pub a: i32, pub b: i32 }
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_unnecessary_braces_in_use_statement() {
|
fn test_check_unnecessary_braces_in_use_statement() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
use a;
|
use a;
|
||||||
use a::{c, d::e};
|
use a::{c, d::e};
|
||||||
@ -509,7 +494,7 @@ mod a {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
use a;
|
use a;
|
||||||
use a::{
|
use a::{
|
||||||
@ -719,7 +704,7 @@ $0
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unlinked_file_with_cfg_on() {
|
fn unlinked_file_with_cfg_on() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
#[cfg(not(never))]
|
#[cfg(not(never))]
|
||||||
|
@ -98,17 +98,17 @@ fn check_pat_field_shorthand(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::diagnostics::tests::{check_fix, check_no_diagnostics};
|
use crate::diagnostics::tests::{check_diagnostics, check_fix};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_expr_field_shorthand() {
|
fn test_check_expr_field_shorthand() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct A { a: &'static str }
|
struct A { a: &'static str }
|
||||||
fn main() { A { a: "hello" } }
|
fn main() { A { a: "hello" } }
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct A(usize);
|
struct A(usize);
|
||||||
fn main() { A { 0: 0 } }
|
fn main() { A { 0: 0 } }
|
||||||
@ -154,13 +154,13 @@ fn main() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_check_pat_field_shorthand() {
|
fn test_check_pat_field_shorthand() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct A { a: &'static str }
|
struct A { a: &'static str }
|
||||||
fn f(a: A) { let A { a: hello } = a; }
|
fn f(a: A) { let A { a: hello } = a; }
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct A(usize);
|
struct A(usize);
|
||||||
fn f(a: A) { let A { 0: 0 } = a; }
|
fn f(a: A) { let A { 0: 0 } = a; }
|
||||||
|
@ -35,7 +35,7 @@ impl DiagnosticWithFixes for IncorrectCase {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod change_case {
|
mod change_case {
|
||||||
use crate::{
|
use crate::{
|
||||||
diagnostics::tests::{check_fix, check_no_diagnostics},
|
diagnostics::tests::{check_diagnostics, check_fix},
|
||||||
fixture, AssistResolveStrategy, DiagnosticsConfig,
|
fixture, AssistResolveStrategy, DiagnosticsConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ fn some_fn() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_uppercase_const_no_diagnostics() {
|
fn test_uppercase_const_no_diagnostics() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
fn foo() {
|
fn foo() {
|
||||||
const ANOTHER_ITEM$0: &str = "some_item";
|
const ANOTHER_ITEM$0: &str = "some_item";
|
||||||
|
@ -25,7 +25,7 @@ impl DiagnosticWithFixes for MissingOkOrSomeInTailExpr {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::diagnostics::tests::{check_fix, check_no_diagnostics};
|
use crate::diagnostics::tests::{check_diagnostics, check_fix};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wrap_return_type_option() {
|
fn test_wrap_return_type_option() {
|
||||||
@ -169,7 +169,7 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
|
fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:core
|
//- /main.rs crate:main deps:core
|
||||||
use core::result::Result::{self, Ok, Err};
|
use core::result::Result::{self, Ok, Err};
|
||||||
@ -189,7 +189,7 @@ pub mod option {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() {
|
fn test_wrap_return_type_not_applicable_when_return_type_is_not_result_or_option() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:core
|
//- /main.rs crate:main deps:core
|
||||||
use core::result::Result::{self, Ok, Err};
|
use core::result::Result::{self, Ok, Err};
|
||||||
|
@ -15,9 +15,7 @@ pub(super) fn macro_error(ctx: &DiagnosticsContext<'_>, d: &hir::MacroError) ->
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
diagnostics::tests::{
|
diagnostics::tests::{check_diagnostics, check_diagnostics_with_config},
|
||||||
check_diagnostics, check_diagnostics_with_config, check_no_diagnostics,
|
|
||||||
},
|
|
||||||
DiagnosticsConfig,
|
DiagnosticsConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +75,7 @@ macro_rules! concat { () => {} }
|
|||||||
fn register_attr_and_tool() {
|
fn register_attr_and_tool() {
|
||||||
cov_mark::check!(register_attr);
|
cov_mark::check!(register_attr);
|
||||||
cov_mark::check!(register_tool);
|
cov_mark::check!(register_tool);
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
#![register_tool(tool)]
|
#![register_tool(tool)]
|
||||||
#![register_attr(attr)]
|
#![register_attr(attr)]
|
||||||
|
@ -77,7 +77,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::diagnostics::tests::{check_diagnostics, check_fix, check_no_diagnostics};
|
use crate::diagnostics::tests::{check_diagnostics, check_fix};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_record_pat_field_diagnostic() {
|
fn missing_record_pat_field_diagnostic() {
|
||||||
@ -203,7 +203,7 @@ fn test_fn() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fill_struct_fields_no_diagnostic() {
|
fn test_fill_struct_fields_no_diagnostic() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct TestStruct { one: i32, two: i64 }
|
struct TestStruct { one: i32, two: i64 }
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ fn test_fn() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fill_struct_fields_no_diagnostic_on_spread() {
|
fn test_fill_struct_fields_no_diagnostic_on_spread() {
|
||||||
check_no_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct TestStruct { one: i32, two: i64 }
|
struct TestStruct { one: i32, two: i64 }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user