aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/grammar/items/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src/grammar/items/mod.rs')
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs
index 883b5a946..fc02f0c5c 100644
--- a/crates/libsyntax2/src/grammar/items/mod.rs
+++ b/crates/libsyntax2/src/grammar/items/mod.rs
@@ -14,13 +14,17 @@ mod use_item;
14pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 14pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
15 attributes::inner_attributes(p); 15 attributes::inner_attributes(p);
16 while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { 16 while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) {
17 item_or_macro(p, stop_on_r_curly) 17 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod)
18 } 18 }
19} 19}
20 20
21pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { 21pub(super) enum ItemFlavor {
22 Mod, Trait
23}
24
25pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
22 let m = p.start(); 26 let m = p.start();
23 match maybe_item(p) { 27 match maybe_item(p, flavor) {
24 MaybeItem::Item(kind) => { 28 MaybeItem::Item(kind) => {
25 m.complete(p, kind); 29 m.complete(p, kind);
26 } 30 }
@@ -60,7 +64,7 @@ pub(super) enum MaybeItem {
60 Modifiers, 64 Modifiers,
61} 65}
62 66
63pub(super) fn maybe_item(p: &mut Parser) -> MaybeItem { 67pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
64 attributes::outer_attributes(p); 68 attributes::outer_attributes(p);
65 visibility(p); 69 visibility(p);
66 if let Some(kind) = items_without_modifiers(p) { 70 if let Some(kind) = items_without_modifiers(p) {
@@ -107,7 +111,7 @@ pub(super) fn maybe_item(p: &mut Parser) -> MaybeItem {
107 // test unsafe_fn 111 // test unsafe_fn
108 // unsafe fn foo() {} 112 // unsafe fn foo() {}
109 FN_KW => { 113 FN_KW => {
110 function(p); 114 function(p, flavor);
111 FN_DEF 115 FN_DEF
112 } 116 }
113 117
@@ -217,7 +221,7 @@ fn extern_block(p: &mut Parser) {
217 p.expect(R_CURLY); 221 p.expect(R_CURLY);
218} 222}
219 223
220fn function(p: &mut Parser) { 224fn function(p: &mut Parser, flavor: ItemFlavor) {
221 assert!(p.at(FN_KW)); 225 assert!(p.at(FN_KW));
222 p.bump(); 226 p.bump();
223 227
@@ -227,7 +231,12 @@ fn function(p: &mut Parser) {
227 type_params::type_param_list(p); 231 type_params::type_param_list(p);
228 232
229 if p.at(L_PAREN) { 233 if p.at(L_PAREN) {
230 params::param_list(p); 234 match flavor {
235 ItemFlavor::Mod =>
236 params::param_list(p),
237 ItemFlavor::Trait =>
238 params::param_list_opt_patterns(p),
239 }
231 } else { 240 } else {
232 p.error("expected function arguments"); 241 p.error("expected function arguments");
233 } 242 }