7722: Fix incorrect missing field diagnostic with box patterns r=Veykril a=lnicola

Closes #7711 

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2021-02-20 10:49:12 +00:00 committed by GitHub
commit 900ba71168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -681,6 +681,30 @@ fn baz(s: S) -> i32 {
)
}
#[test]
fn missing_record_pat_field_box() {
check_diagnostics(
r"
struct S { s: Box<u32> }
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(

View File

@ -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
}
}