]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/tests.rs
Merge #11842
[rust.git] / crates / hir_ty / src / tests.rs
index af6e7732177df4bdfe885ee1711a9981260e2707..d2f13e4351c73b17cca725446ddfcbd772988e4f 100644 (file)
@@ -8,6 +8,7 @@
 mod macros;
 mod display_source_code;
 mod incremental;
+mod diagnostics;
 
 use std::{collections::HashMap, env, sync::Arc};
 
@@ -26,7 +27,7 @@
 use once_cell::race::OnceBool;
 use stdx::format_to;
 use syntax::{
-    ast::{self, AstNode, NameOwner},
+    ast::{self, AstNode, HasName},
     SyntaxNode,
 };
 use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
@@ -100,6 +101,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
                         .trim_start_matches("adjustments: ")
                         .split(',')
                         .map(|it| it.trim().to_string())
+                        .filter(|it| !it.is_empty())
                         .collect(),
                 );
             } else {
@@ -195,10 +197,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
                 mismatch.expected.display_test(&db),
                 mismatch.actual.display_test(&db)
             );
-            if let Some(annotation) = mismatches.remove(&range) {
-                assert_eq!(actual, annotation);
-            } else {
-                format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
+            match mismatches.remove(&range) {
+                Some(annotation) => assert_eq!(actual, annotation),
+                None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
             }
         }
         for (expr, mismatch) in inference_result.expr_type_mismatches() {
@@ -215,10 +216,9 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
                 mismatch.expected.display_test(&db),
                 mismatch.actual.display_test(&db)
             );
-            if let Some(annotation) = mismatches.remove(&range) {
-                assert_eq!(actual, annotation);
-            } else {
-                format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual);
+            match mismatches.remove(&range) {
+                Some(annotation) => assert_eq!(actual, annotation),
+                None => format_to!(unexpected_type_mismatches, "{:?}: {}\n", range.range, actual),
             }
         }
     }
@@ -338,7 +338,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
             let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.value.clone()) {
                 (self_param.name().unwrap().syntax().text_range(), "self".to_string())
             } else {
-                (node.value.text_range(), node.value.text().to_string().replace("\n", " "))
+                (node.value.text_range(), node.value.text().to_string().replace('\n', " "))
             };
             let macro_prefix = if node.file_id != file_id.into() { "!" } else { "" };
             format_to!(