diff options
author | pcpthm <[email protected]> | 2019-03-18 04:03:04 +0000 |
---|---|---|
committer | pcpthm <[email protected]> | 2019-03-18 04:14:47 +0000 |
commit | 3d9c2beb8e0d4e0fbaded7dac259cadf7616a3ad (patch) | |
tree | d0d7a91f282537c3294f3b5b3a283dfd5faaa1a6 /crates/ra_parser/src/grammar/items.rs | |
parent | e5702675155a5db137af65cf9d62cba4a6cea6c0 (diff) |
Apply stylistic changes suggested
Diffstat (limited to 'crates/ra_parser/src/grammar/items.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 23 |
1 files changed, 10 insertions, 13 deletions
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 | ||
37 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { | 37 | pub(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 | ||
69 | pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Option<Marker> { | 69 | pub(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 | ||
169 | fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> { | 166 | fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> { |