aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs2
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs23
-rw-r--r--crates/libsyntax2/src/grammar/items/traits.rs4
3 files changed, 19 insertions, 10 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs
index af9f47c5e..e62b16654 100644
--- a/crates/libsyntax2/src/grammar/expressions/atom.rs
+++ b/crates/libsyntax2/src/grammar/expressions/atom.rs
@@ -284,7 +284,7 @@ pub(super) fn block_expr(p: &mut Parser) -> CompletedMarker {
284 // test block_items 284 // test block_items
285 // fn a() { fn b() {} } 285 // fn a() { fn b() {} }
286 let m = p.start(); 286 let m = p.start();
287 match items::maybe_item(p) { 287 match items::maybe_item(p, items::ItemFlavor::Mod) {
288 items::MaybeItem::Item(kind) => { 288 items::MaybeItem::Item(kind) => {
289 m.complete(p, kind); 289 m.complete(p, kind);
290 } 290 }
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 }
diff --git a/crates/libsyntax2/src/grammar/items/traits.rs b/crates/libsyntax2/src/grammar/items/traits.rs
index 53a636f6c..daecaff5c 100644
--- a/crates/libsyntax2/src/grammar/items/traits.rs
+++ b/crates/libsyntax2/src/grammar/items/traits.rs
@@ -20,7 +20,7 @@ pub(super) fn trait_def(p: &mut Parser) {
20 // fn bar(&self); 20 // fn bar(&self);
21 // } 21 // }
22 while !p.at(EOF) && !p.at(R_CURLY) { 22 while !p.at(EOF) && !p.at(R_CURLY) {
23 item_or_macro(p, true); 23 item_or_macro(p, true, ItemFlavor::Trait);
24 } 24 }
25 p.expect(R_CURLY); 25 p.expect(R_CURLY);
26} 26}
@@ -55,7 +55,7 @@ pub(super) fn impl_item(p: &mut Parser) {
55 // fn bar(&self) {} 55 // fn bar(&self) {}
56 // } 56 // }
57 while !p.at(EOF) && !p.at(R_CURLY) { 57 while !p.at(EOF) && !p.at(R_CURLY) {
58 item_or_macro(p, true); 58 item_or_macro(p, true, ItemFlavor::Mod);
59 } 59 }
60 p.expect(R_CURLY); 60 p.expect(R_CURLY);
61} 61}