diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-20 10:49:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-20 10:49:12 +0000 |
commit | 900ba711683e23a3e322730e6b7a913b350379eb (patch) | |
tree | 8b644487b66e8c085747429a46ef5745f39b1cc3 | |
parent | 20a911f3cc2beb0409ab71cc1560648374745f7f (diff) | |
parent | c1d37f030f01b5227168a822ed61cb27e6c67429 (diff) |
Merge #7722
7722: Fix incorrect missing field diagnostic with box patterns r=Veykril a=lnicola
Closes #7711
Co-authored-by: Laurențiu Nicola <[email protected]>
-rw-r--r-- | crates/hir_ty/src/diagnostics.rs | 24 | ||||
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 17 |
2 files changed, 37 insertions, 4 deletions
diff --git a/crates/hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs index 19da51acd..6bca7aa0d 100644 --- a/crates/hir_ty/src/diagnostics.rs +++ b/crates/hir_ty/src/diagnostics.rs | |||
@@ -682,6 +682,30 @@ fn baz(s: S) -> i32 { | |||
682 | } | 682 | } |
683 | 683 | ||
684 | #[test] | 684 | #[test] |
685 | fn missing_record_pat_field_box() { | ||
686 | check_diagnostics( | ||
687 | r" | ||
688 | struct S { s: Box<u32> } | ||
689 | fn x(a: S) { | ||
690 | let S { box s } = a; | ||
691 | } | ||
692 | ", | ||
693 | ) | ||
694 | } | ||
695 | |||
696 | #[test] | ||
697 | fn missing_record_pat_field_ref() { | ||
698 | check_diagnostics( | ||
699 | r" | ||
700 | struct S { s: u32 } | ||
701 | fn x(a: S) { | ||
702 | let S { ref s } = a; | ||
703 | } | ||
704 | ", | ||
705 | ) | ||
706 | } | ||
707 | |||
708 | #[test] | ||
685 | fn break_outside_of_loop() { | 709 | fn break_outside_of_loop() { |
686 | check_diagnostics( | 710 | check_diagnostics( |
687 | r#" | 711 | r#" |
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 2fa7b8c1e..52ac97c84 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -381,11 +381,20 @@ impl ast::RecordPatField { | |||
381 | if let Some(name_ref) = self.name_ref() { | 381 | if let Some(name_ref) = self.name_ref() { |
382 | return Some(NameOrNameRef::NameRef(name_ref)); | 382 | return Some(NameOrNameRef::NameRef(name_ref)); |
383 | } | 383 | } |
384 | if let Some(ast::Pat::IdentPat(pat)) = self.pat() { | 384 | match self.pat() { |
385 | let name = pat.name()?; | 385 | Some(ast::Pat::IdentPat(pat)) => { |
386 | return Some(NameOrNameRef::Name(name)); | 386 | let name = pat.name()?; |
387 | Some(NameOrNameRef::Name(name)) | ||
388 | } | ||
389 | Some(ast::Pat::BoxPat(pat)) => match pat.pat() { | ||
390 | Some(ast::Pat::IdentPat(pat)) => { | ||
391 | let name = pat.name()?; | ||
392 | Some(NameOrNameRef::Name(name)) | ||
393 | } | ||
394 | _ => None, | ||
395 | }, | ||
396 | _ => None, | ||
387 | } | 397 | } |
388 | None | ||
389 | } | 398 | } |
390 | } | 399 | } |
391 | 400 | ||