From af4148970a800b8df733f961b14403b800d3fb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 20 Feb 2021 12:36:17 +0200 Subject: Fix incorrect missing field diagnostic with box patterns --- crates/syntax/src/ast/node_ext.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'crates') 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 { if let Some(name_ref) = self.name_ref() { return Some(NameOrNameRef::NameRef(name_ref)); } - if let Some(ast::Pat::IdentPat(pat)) = self.pat() { - let name = pat.name()?; - return Some(NameOrNameRef::Name(name)); + match self.pat() { + Some(ast::Pat::IdentPat(pat)) => { + let name = pat.name()?; + Some(NameOrNameRef::Name(name)) + } + Some(ast::Pat::BoxPat(pat)) => match pat.pat() { + Some(ast::Pat::IdentPat(pat)) => { + let name = pat.name()?; + Some(NameOrNameRef::Name(name)) + } + _ => None, + }, + _ => None, } - None } } -- cgit v1.2.3 From c1d37f030f01b5227168a822ed61cb27e6c67429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 20 Feb 2021 12:43:52 +0200 Subject: Add test --- crates/hir_ty/src/diagnostics.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'crates') 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 @@ -681,6 +681,30 @@ fn baz(s: S) -> i32 { ) } + #[test] + fn missing_record_pat_field_box() { + check_diagnostics( + r" +struct S { s: Box } +fn x(a: S) { + let S { box s } = a; +} +", + ) + } + + #[test] + fn missing_record_pat_field_ref() { + check_diagnostics( + r" +struct S { s: u32 } +fn x(a: S) { + let S { ref s } = a; +} +", + ) + } + #[test] fn break_outside_of_loop() { check_diagnostics( -- cgit v1.2.3