10420: Parse outer attributes on StructPatternEtCetera r=jonas-schievink a=XFFXFF

Try to fix https://github.com/rust-analyzer/rust-analyzer/issues/8610  
Related pr in ungrammer: https://github.com/rust-analyzer/ungrammar/pull/41

Co-authored-by: zhoufan <1247714429@qq.com>
This commit is contained in:
bors[bot] 2021-10-06 15:05:40 +00:00 committed by GitHub
commit 94fa49c0a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 37 deletions

View file

@ -205,46 +205,64 @@ fn tuple_pat_fields(p: &mut Parser) {
p.expect(T![')']);
}
// test record_pat_field
// fn foo() {
// let S { 0: 1 } = ();
// let S { x: 1 } = ();
// let S { #[cfg(any())] x: 1 } = ();
// }
fn record_pat_field(p: &mut Parser) {
match p.current() {
IDENT | INT_NUMBER if p.nth(1) == T![:] => {
name_ref_or_index(p);
p.bump(T![:]);
pattern(p);
}
T![.] => {
if p.at(T![..]) {
p.bump(T![..]);
} else {
ident_pat(p, false);
}
}
T![box] => {
// FIXME: not all box patterns should be allowed
box_pat(p);
}
_ => {
ident_pat(p, false);
}
}
}
// test record_pat_field_list
// fn foo() {
// let S {} = ();
// let S { f, ref mut g } = ();
// let S { h: _, ..} = ();
// let S { h: _, } = ();
// let S { #[cfg(any())] .. } = ();
// }
fn record_pat_field_list(p: &mut Parser) {
assert!(p.at(T!['{']));
let m = p.start();
p.bump(T!['{']);
while !p.at(EOF) && !p.at(T!['}']) {
let m = p.start();
attributes::outer_attrs(p);
match p.current() {
// A trailing `..` is *not* treated as a REST_PAT.
T![.] if p.at(T![..]) => p.bump(T![..]),
T!['{'] => error_block(p, "expected ident"),
T![.] if p.at(T![..]) => {
p.bump(T![..]);
m.complete(p, REST_PAT);
}
T!['{'] => {
error_block(p, "expected ident");
m.abandon(p);
}
_ => {
let m = p.start();
attributes::outer_attrs(p);
match p.current() {
// test record_pat_field
// fn foo() {
// let S { 0: 1 } = ();
// let S { x: 1 } = ();
// let S { #[cfg(any())] x: 1 } = ();
// }
IDENT | INT_NUMBER if p.nth(1) == T![:] => {
name_ref_or_index(p);
p.bump(T![:]);
pattern(p);
}
T![box] => {
// FIXME: not all box patterns should be allowed
box_pat(p);
}
_ => {
ident_pat(p, false);
}
}
record_pat_field(p);
m.complete(p, RECORD_PAT_FIELD);
}
}