Unnamed repository; edit this file 'description' to name the repository.
15 files changed, 133 insertions, 219 deletions
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 78d99f284a..13d9f9e1ab 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -148,14 +148,13 @@ pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { // impl T for Foo { // default async fn foo() {} // } - - // test default_async_unsafe_fn - // impl T for Foo { - // default async unsafe fn foo() {} - // } T![async] => { let mut maybe_fn = p.nth(2); let is_unsafe = if matches!(maybe_fn, T![unsafe]) { + // test default_async_unsafe_fn + // impl T for Foo { + // default async unsafe fn foo() {} + // } maybe_fn = p.nth(3); true } else { @@ -400,9 +399,9 @@ fn fn_(p: &mut Parser, m: Marker) { // fn foo<T>() where T: Copy {} type_params::opt_where_clause(p); - // test fn_decl - // trait T { fn foo(); } if p.at(T![;]) { + // test fn_decl + // trait T { fn foo(); } p.bump(T![;]); } else { expressions::block_expr(p) diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs index eaf16bc1a1..e870de9de0 100644 --- a/crates/parser/src/grammar/items/adt.rs +++ b/crates/parser/src/grammar/items/adt.rs @@ -22,9 +22,7 @@ fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { T![where] => { type_params::opt_where_clause(p); match p.current() { - T![;] => { - p.bump(T![;]); - } + T![;] => p.bump(T![;]), T!['{'] => record_field_list(p), _ => { //FIXME: special case `(` error message @@ -53,7 +51,6 @@ fn struct_or_union(p: &mut Parser, m: Marker, is_struct: bool) { } pub(super) fn enum_(p: &mut Parser, m: Marker) { - assert!(p.at(T![enum])); p.bump(T![enum]); name_r(p, ITEM_RECOVERY_SET); type_params::opt_generic_param_list(p); @@ -75,7 +72,16 @@ pub(crate) fn variant_list(p: &mut Parser) { error_block(p, "expected enum variant"); continue; } - let var = p.start(); + variant(p); + if !p.at(T!['}']) { + p.expect(T![,]); + } + } + p.expect(T!['}']); + m.complete(p, VARIANT_LIST); + + fn variant(p: &mut Parser) { + let m = p.start(); attributes::outer_attrs(p); if p.at(IDENT) { name(p); @@ -90,17 +96,12 @@ pub(crate) fn variant_list(p: &mut Parser) { if p.eat(T![=]) { expressions::expr(p); } - var.complete(p, VARIANT); + m.complete(p, VARIANT); } else { - var.abandon(p); + m.abandon(p); p.err_and_bump("expected enum variant"); } - if !p.at(T!['}']) { - p.expect(T![,]); - } } - p.expect(T!['}']); - m.complete(p, VARIANT_LIST); } // test record_field_list @@ -114,7 +115,7 @@ pub(crate) fn record_field_list(p: &mut Parser) { error_block(p, "expected field"); continue; } - record_field_def(p); + record_field(p); if !p.at(T!['}']) { p.expect(T![,]); } @@ -122,13 +123,10 @@ pub(crate) fn record_field_list(p: &mut Parser) { p.expect(T!['}']); m.complete(p, RECORD_FIELD_LIST); - fn record_field_def(p: &mut Parser) { + fn record_field(p: &mut Parser) { let m = p.start(); // test record_field_attrs - // struct S { - // #[serde(with = "url_serde")] - // pub uri: Uri, - // } + // struct S { #[attr] f: f32 } attributes::outer_attrs(p); opt_visibility(p); if p.at(IDENT) { @@ -146,20 +144,11 @@ pub(crate) fn record_field_list(p: &mut Parser) { fn tuple_field_list(p: &mut Parser) { assert!(p.at(T!['('])); let m = p.start(); - if !p.expect(T!['(']) { - return; - } + p.bump(T!['(']); while !p.at(T![')']) && !p.at(EOF) { let m = p.start(); // test tuple_field_attrs - // struct S ( - // #[serde(with = "url_serde")] - // pub Uri, - // ); - // - // enum S { - // Uri(#[serde(with = "url_serde")] Uri), - // } + // struct S (#[attr] f32); attributes::outer_attrs(p); opt_visibility(p); if !p.at_ts(types::TYPE_FIRST) { diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs index 1b317dd84a..93ba7d05fe 100644 --- a/crates/parser/src/grammar/items/consts.rs +++ b/crates/parser/src/grammar/items/consts.rs @@ -1,26 +1,29 @@ use super::*; -pub(super) fn static_(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![static], STATIC) +// test const_item +// const C: u32 = 92; +pub(super) fn konst(p: &mut Parser, m: Marker) { + p.bump(T![const]); + const_or_static(p, m, true) } -pub(super) fn konst(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![const], CONST) +pub(super) fn static_(p: &mut Parser, m: Marker) { + p.bump(T![static]); + const_or_static(p, m, false) } -fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { - assert!(p.at(kw)); - p.bump(kw); +fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) { p.eat(T![mut]); - // Allow `_` in place of an identifier in a `const`. - let is_const_underscore = kw == T![const] && p.eat(T![_]); - if !is_const_underscore { + if is_const && p.eat(T![_]) { + // test anonymous_const + // const _: u32 = 0; + } else { + // test_err anonymous_static + // static _: i32 = 5; name(p); } - // test_err static_underscore - // static _: i32 = 5; if p.at(T![:]) { types::ascription(p); } else { @@ -30,5 +33,5 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { expressions::expr(p); } p.expect(T![;]); - m.complete(p, def); + m.complete(p, if is_const { CONST } else { STATIC }); } diff --git a/crates/syntax/test_data/parser/inline/err/0013_static_underscore.rast b/crates/syntax/test_data/parser/inline/err/0013_anonymous_static.rast index 8d761b9074..8d761b9074 100644 --- a/crates/syntax/test_data/parser/inline/err/0013_static_underscore.rast +++ b/crates/syntax/test_data/parser/inline/err/0013_anonymous_static.rast diff --git a/crates/syntax/test_data/parser/inline/err/0013_static_underscore.rs b/crates/syntax/test_data/parser/inline/err/0013_anonymous_static.rs index df8cecb432..df8cecb432 100644 --- a/crates/syntax/test_data/parser/inline/err/0013_static_underscore.rs +++ b/crates/syntax/test_data/parser/inline/err/0013_anonymous_static.rs diff --git a/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast index 402950bcc9..453bef3158 100644 --- a/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast +++ b/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rast @@ -1,45 +1,33 @@ [email protected] "struct" - [email protected] "\n " - [email protected] "#" - [email protected] "[" - [email protected] "serde" - [email protected] "(" - [email protected] "with" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "\"url_serde\"" - [email protected] ")" - [email protected] "]" - [email protected] "\n " - [email protected] "pub" - [email protected] " " - [email protected] "uri" - [email protected] ":" - [email protected] " " - [email protected] "Uri" - [email protected] "," - [email protected] "\n" - [email protected] "}" - [email protected] "\n" + [email protected] " " + [email protected] "#" + [email protected] "[" + [email protected] "attr" + [email protected] "]" + [email protected] " " + [email protected] "f" + [email protected] ":" + [email protected] " " + [email protected] "f32" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rs index 4744d8ac06..d7f0b4382d 100644 --- a/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rs +++ b/crates/syntax/test_data/parser/inline/ok/0054_record_field_attrs.rs @@ -1,4 +1 @@ -struct S { - #[serde(with = "url_serde")] - pub uri: Uri, -} +struct S { #[attr] f: f32 } diff --git a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast index 533f738e15..9a0bcdc18e 100644 --- a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast +++ b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rast @@ -1,85 +1,28 @@ [email protected] "struct" - [email protected] "\n " - [email protected] "#" - [email protected] "[" - [email protected] "serde" - [email protected] "(" - [email protected] "with" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "\"url_serde\"" - [email protected] ")" - [email protected] "]" - [email protected] "\n " - [email protected] "pub" - [email protected] " " - [email protected] "Uri" - [email protected] "," - [email protected] "\n" - [email protected] ")" - [email protected] ";" - [email protected] "\n\n" - [email protected] "enum" - [email protected] " " - [email protected] "S" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "Uri" - [email protected] "(" - [email protected] "#" - [email protected] "[" - [email protected] "serde" - [email protected] "(" - [email protected] "with" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "\"url_serde\"" - [email protected] ")" - [email protected] "]" - [email protected] " " - [email protected] "Uri" - [email protected] ")" - [email protected] "," - [email protected] "\n" - [email protected] "}" - [email protected] "\n" + [email protected] "#" + [email protected] "[" + [email protected] "attr" + [email protected] "]" + [email protected] " " + [email protected] "f32" + [email protected] ")" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs index 4da379d0ed..648ffe5654 100644 --- a/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs +++ b/crates/syntax/test_data/parser/inline/ok/0115_tuple_field_attrs.rs @@ -1,8 +1 @@ -struct S ( - #[serde(with = "url_serde")] - pub Uri, -); - -enum S { - Uri(#[serde(with = "url_serde")] Uri), -} +struct S (#[attr] f32); diff --git a/crates/syntax/test_data/parser/inline/ok/0172_const_item.rast b/crates/syntax/test_data/parser/inline/ok/0172_const_item.rast new file mode 100644 index 0000000000..8a61d5e566 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0172_const_item.rast @@ -0,0 +1,20 @@ + [email protected] "const" + [email protected] " " + [email protected] "C" + [email protected] ":" + [email protected] " " + [email protected] "u32" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "92" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0172_const_item.rs b/crates/syntax/test_data/parser/inline/ok/0172_const_item.rs new file mode 100644 index 0000000000..6d5f5be65d --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0172_const_item.rs @@ -0,0 +1 @@ +const C: u32 = 92; diff --git a/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rast b/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rast new file mode 100644 index 0000000000..68ce503c39 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rast @@ -0,0 +1,19 @@ + [email protected] "const" + [email protected] " " + [email protected] "_" + [email protected] ":" + [email protected] " " + [email protected] "u32" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "0" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rs b/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rs new file mode 100644 index 0000000000..c1d5cdfc62 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0173_anonymous_const.rs @@ -0,0 +1 @@ +const _: u32 = 0; diff --git a/crates/syntax/test_data/parser/ok/0024_const_item.rast b/crates/syntax/test_data/parser/ok/0024_const_item.rast index b89ed6f98e..6b234b0b24 100644 --- a/crates/syntax/test_data/parser/ok/0024_const_item.rast +++ b/crates/syntax/test_data/parser/ok/0024_const_item.rast @@ -1,38 +1 @@ - [email protected] "const" - [email protected] " " - [email protected] "_" - [email protected] ":" - [email protected] " " - [email protected] "u32" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "0" - [email protected] ";" - [email protected] "\n" - [email protected] "const" - [email protected] " " - [email protected] "FOO" - [email protected] ":" - [email protected] " " - [email protected] "u32" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "92" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/ok/0024_const_item.rs b/crates/syntax/test_data/parser/ok/0024_const_item.rs index 1f2ffa0da3..e69de29bb2 100644 --- a/crates/syntax/test_data/parser/ok/0024_const_item.rs +++ b/crates/syntax/test_data/parser/ok/0024_const_item.rs @@ -1,2 +0,0 @@ -const _: u32 = 0; -const FOO: u32 = 92; |