aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r--crates/ra_hir_ty/src/tests.rs46
1 files changed, 42 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index 002cffba6..81fc0f63a 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -82,12 +82,10 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
82 82
83 for (expr, ty) in inference_result.type_of_expr.iter() { 83 for (expr, ty) in inference_result.type_of_expr.iter() {
84 let syntax_ptr = match body_source_map.expr_syntax(expr) { 84 let syntax_ptr = match body_source_map.expr_syntax(expr) {
85 Ok(sp) => { 85 Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()),
86 sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()))
87 }
88 Err(SyntheticSyntax) => continue, 86 Err(SyntheticSyntax) => continue,
89 }; 87 };
90 types.push((syntax_ptr, ty)); 88 types.push((syntax_ptr.clone(), ty));
91 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) { 89 if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) {
92 mismatches.push((syntax_ptr, mismatch)); 90 mismatches.push((syntax_ptr, mismatch));
93 } 91 }
@@ -409,3 +407,43 @@ fn no_such_field_with_feature_flag_diagnostics_on_struct_fields() {
409 407
410 assert_snapshot!(diagnostics, @r###""###); 408 assert_snapshot!(diagnostics, @r###""###);
411} 409}
410
411#[test]
412fn missing_record_pat_field_diagnostic() {
413 let diagnostics = TestDB::with_files(
414 r"
415 //- /lib.rs
416 struct S { foo: i32, bar: () }
417 fn baz(s: S) {
418 let S { foo: _ } = s;
419 }
420 ",
421 )
422 .diagnostics()
423 .0;
424
425 assert_snapshot!(diagnostics, @r###"
426 "{ foo: _ }": Missing structure fields:
427 - bar
428 "###
429 );
430}
431
432#[test]
433fn missing_record_pat_field_no_diagnostic_if_not_exhaustive() {
434 let diagnostics = TestDB::with_files(
435 r"
436 //- /lib.rs
437 struct S { foo: i32, bar: () }
438 fn baz(s: S) -> i32 {
439 match s {
440 S { foo, .. } => foo,
441 }
442 }
443 ",
444 )
445 .diagnostics()
446 .0;
447
448 assert_snapshot!(diagnostics, @"");
449}