aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs8
-rw-r--r--crates/ra_parser/src/grammar/items.rs23
2 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 9839846f1..6d3e379a3 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -54,7 +54,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
54 54
55 // test block_items 55 // test block_items
56 // fn a() { fn b() {} } 56 // fn a() { fn b() {} }
57 let mut m = p.start(); 57 let m = p.start();
58 let has_attrs = p.at(POUND); 58 let has_attrs = p.at(POUND);
59 attributes::outer_attributes(p); 59 attributes::outer_attributes(p);
60 if p.at(LET_KW) { 60 if p.at(LET_KW) {
@@ -62,9 +62,9 @@ pub(crate) fn expr_block_contents(p: &mut Parser) {
62 continue; 62 continue;
63 } 63 }
64 64
65 m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { 65 let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) {
66 Some(m) => m, 66 Ok(()) => continue,
67 None => continue, 67 Err(m) => m,
68 }; 68 };
69 69
70 // test pub_expr 70 // test pub_expr
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 5411589dd..94b93a02b 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -35,11 +35,11 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
35]; 35];
36 36
37pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { 37pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
38 let mut m = p.start(); 38 let m = p.start();
39 attributes::outer_attributes(p); 39 attributes::outer_attributes(p);
40 m = match maybe_item(p, m, flavor) { 40 let m = match maybe_item(p, m, flavor) {
41 Some(m) => m, 41 Ok(()) => return,
42 None => return, 42 Err(m) => m,
43 }; 43 };
44 if paths::is_path_start(p) { 44 if paths::is_path_start(p) {
45 match macro_call(p) { 45 match macro_call(p) {
@@ -66,11 +66,11 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
66 } 66 }
67} 67}
68 68
69pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Option<Marker> { 69pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> {
70 opt_visibility(p); 70 opt_visibility(p);
71 if let Some(kind) = items_without_modifiers(p) { 71 if let Some(kind) = items_without_modifiers(p) {
72 m.complete(p, kind); 72 m.complete(p, kind);
73 return None; 73 return Ok(());
74 } 74 }
75 75
76 let mut has_mods = false; 76 let mut has_mods = false;
@@ -124,7 +124,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio
124 FN_KW => { 124 FN_KW => {
125 fn_def(p, flavor); 125 fn_def(p, flavor);
126 m.complete(p, FN_DEF); 126 m.complete(p, FN_DEF);
127 None
128 } 127 }
129 128
130 // test unsafe_trait 129 // test unsafe_trait
@@ -138,7 +137,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio
138 TRAIT_KW => { 137 TRAIT_KW => {
139 traits::trait_def(p); 138 traits::trait_def(p);
140 m.complete(p, TRAIT_DEF); 139 m.complete(p, TRAIT_DEF);
141 None
142 } 140 }
143 141
144 // test unsafe_impl 142 // test unsafe_impl
@@ -152,18 +150,17 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio
152 IMPL_KW => { 150 IMPL_KW => {
153 traits::impl_block(p); 151 traits::impl_block(p);
154 m.complete(p, IMPL_BLOCK); 152 m.complete(p, IMPL_BLOCK);
155 None
156 } 153 }
157 _ => { 154 _ => {
158 if has_mods { 155 if !has_mods {
156 return Err(m);
157 } else {
159 p.error("expected fn, trait or impl"); 158 p.error("expected fn, trait or impl");
160 m.complete(p, ERROR); 159 m.complete(p, ERROR);
161 None
162 } else {
163 Some(m)
164 } 160 }
165 } 161 }
166 } 162 }
163 Ok(())
167} 164}
168 165
169fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> { 166fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {