]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/rust-analyzer/crates/hir-ty/src/tests.rs
Auto merge of #107843 - bjorn3:sync_cg_clif-2023-02-09, r=bjorn3
[rust.git] / src / tools / rust-analyzer / crates / hir-ty / src / tests.rs
index ebbc5410147c6b8d63e8b4df5623fba06db5b4d5..ba5d9c2412670851fc255c0bad858b70e88644b8 100644 (file)
@@ -94,18 +94,19 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
                 types.insert(file_range, expected.trim_start_matches("type: ").to_string());
             } else if expected.starts_with("expected") {
                 mismatches.insert(file_range, expected);
-            } else if expected.starts_with("adjustments: ") {
+            } else if expected.starts_with("adjustments:") {
                 adjustments.insert(
                     file_range,
                     expected
-                        .trim_start_matches("adjustments: ")
+                        .trim_start_matches("adjustments:")
+                        .trim()
                         .split(',')
                         .map(|it| it.trim().to_string())
                         .filter(|it| !it.is_empty())
                         .collect(),
                 );
             } else {
-                panic!("unexpected annotation: {}", expected);
+                panic!("unexpected annotation: {expected}");
             }
             had_annotations = true;
         }
@@ -176,17 +177,17 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
                 assert_eq!(actual, expected);
             }
             if let Some(expected) = adjustments.remove(&range) {
-                if let Some(adjustments) = inference_result.expr_adjustments.get(&expr) {
-                    assert_eq!(
-                        expected,
-                        adjustments
-                            .iter()
-                            .map(|Adjustment { kind, .. }| format!("{:?}", kind))
-                            .collect::<Vec<_>>()
-                    );
-                } else {
-                    panic!("expected {:?} adjustments, found none", expected);
-                }
+                let adjustments = inference_result
+                    .expr_adjustments
+                    .get(&expr)
+                    .map_or_else(Default::default, |it| &**it);
+                assert_eq!(
+                    expected,
+                    adjustments
+                        .iter()
+                        .map(|Adjustment { kind, .. }| format!("{kind:?}"))
+                        .collect::<Vec<_>>()
+                );
             }
         }