mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Parse outer attributes on StructPatternEtCetera
This commit is contained in:
parent
237ea0d34d
commit
0ee6b70b34
6 changed files with 103 additions and 32 deletions
|
@ -200,12 +200,43 @@ 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!['{']));
|
||||
|
@ -214,32 +245,26 @@ fn record_pat_field_list(p: &mut Parser) {
|
|||
while !p.at(EOF) && !p.at(T!['}']) {
|
||||
match p.current() {
|
||||
// A trailing `..` is *not* treated as a REST_PAT.
|
||||
T![.] if p.at(T![..]) => p.bump(T![..]),
|
||||
T![.] if p.at(T![..]) => {
|
||||
rest_pat(p);
|
||||
}
|
||||
T!['{'] => error_block(p, "expected ident"),
|
||||
T![#] => {
|
||||
let m = p.start();
|
||||
attributes::outer_attrs(p);
|
||||
if p.at(T![..]) {
|
||||
p.bump(T![..]);
|
||||
m.complete(p, REST_PAT);
|
||||
} else {
|
||||
record_pat_field(p);
|
||||
m.complete(p, RECORD_PAT_FIELD);
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue