mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 11:24:24 +00:00
Merge #10420
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:
commit
94fa49c0a3
7 changed files with 101 additions and 37 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue