Skip to content

Commit 900ba71

Browse files
bors[bot]lnicola
andauthored
Merge #7722
7722: Fix incorrect missing field diagnostic with box patterns r=Veykril a=lnicola Closes #7711 Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2 parents 20a911f + c1d37f0 commit 900ba71

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

crates/hir_ty/src/diagnostics.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,30 @@ fn baz(s: S) -> i32 {
681681
)
682682
}
683683

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+
684708
#[test]
685709
fn break_outside_of_loop() {
686710
check_diagnostics(

crates/syntax/src/ast/node_ext.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,20 @@ impl ast::RecordPatField {
381381
if let Some(name_ref) = self.name_ref() {
382382
return Some(NameOrNameRef::NameRef(name_ref));
383383
}
384-
if let Some(ast::Pat::IdentPat(pat)) = self.pat() {
385-
let name = pat.name()?;
386-
return Some(NameOrNameRef::Name(name));
384+
match self.pat() {
385+
Some(ast::Pat::IdentPat(pat)) => {
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,
387397
}
388-
None
389398
}
390399
}
391400

0 commit comments

Comments
 (0)