diff options
author | Aleksey Kladov <[email protected]> | 2020-08-12 13:26:36 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-12 13:28:32 +0100 |
commit | f73a6419d43b21d07b7ee5d3804bdd586ee8036f (patch) | |
tree | c50a6d1bbb31debeaf9a0244f5dab4887b41c266 /crates/ra_parser/src/grammar/items.rs | |
parent | 4b3d99f98f393d1c05b1041d3178cae45ebcd3ff (diff) |
Allow default everywhere
closes #5681
Diffstat (limited to 'crates/ra_parser/src/grammar/items.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index cca524cea..9b7623434 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -22,24 +22,19 @@ use super::*; | |||
22 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { | 22 | pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { |
23 | attributes::inner_attributes(p); | 23 | attributes::inner_attributes(p); |
24 | while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { | 24 | while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { |
25 | item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) | 25 | item_or_macro(p, stop_on_r_curly) |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | pub(super) enum ItemFlavor { | ||
30 | Mod, | ||
31 | Trait, | ||
32 | } | ||
33 | |||
34 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ | 29 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ |
35 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, | 30 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, |
36 | CRATE_KW, USE_KW, MACRO_KW | 31 | CRATE_KW, USE_KW, MACRO_KW |
37 | ]; | 32 | ]; |
38 | 33 | ||
39 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { | 34 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) { |
40 | let m = p.start(); | 35 | let m = p.start(); |
41 | attributes::outer_attributes(p); | 36 | attributes::outer_attributes(p); |
42 | let m = match maybe_item(p, m, flavor) { | 37 | let m = match maybe_item(p, m) { |
43 | Ok(()) => { | 38 | Ok(()) => { |
44 | if p.at(T![;]) { | 39 | if p.at(T![;]) { |
45 | p.err_and_bump( | 40 | p.err_and_bump( |
@@ -76,7 +71,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF | |||
76 | } | 71 | } |
77 | } | 72 | } |
78 | 73 | ||
79 | pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> { | 74 | pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { |
80 | // test_err pub_expr | 75 | // test_err pub_expr |
81 | // fn foo() { pub 92; } | 76 | // fn foo() { pub 92; } |
82 | let has_visibility = opt_visibility(p); | 77 | let has_visibility = opt_visibility(p); |
@@ -114,38 +109,29 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul | |||
114 | has_mods = true; | 109 | has_mods = true; |
115 | } | 110 | } |
116 | 111 | ||
117 | if p.at(IDENT) | 112 | // test default_item |
118 | && p.at_contextual_kw("default") | 113 | // default impl T for Foo {} |
119 | && (match p.nth(1) { | 114 | if p.at(IDENT) && p.at_contextual_kw("default") { |
120 | T![impl] => true, | 115 | match p.nth(1) { |
116 | T![fn] | T![type] | T![const] | T![impl] => { | ||
117 | p.bump_remap(T![default]); | ||
118 | has_mods = true; | ||
119 | } | ||
121 | T![unsafe] => { | 120 | T![unsafe] => { |
122 | // test default_unsafe_impl | 121 | // test default_unsafe_item |
123 | // default unsafe impl Foo {} | 122 | // default unsafe impl T for Foo { |
124 | |||
125 | // test default_unsafe_fn | ||
126 | // impl T for Foo { | ||
127 | // default unsafe fn foo() {} | 123 | // default unsafe fn foo() {} |
128 | // } | 124 | // } |
129 | if p.nth(2) == T![impl] || p.nth(2) == T![fn] { | 125 | if matches!(p.nth(2), T![impl] | T![fn]) { |
130 | p.bump_remap(T![default]); | 126 | p.bump_remap(T![default]); |
131 | p.bump(T![unsafe]); | 127 | p.bump(T![unsafe]); |
132 | has_mods = true; | 128 | has_mods = true; |
133 | } | 129 | } |
134 | false | ||
135 | } | ||
136 | T![fn] | T![type] | T![const] => { | ||
137 | if let ItemFlavor::Mod = flavor { | ||
138 | true | ||
139 | } else { | ||
140 | false | ||
141 | } | ||
142 | } | 130 | } |
143 | _ => false, | 131 | _ => (), |
144 | }) | 132 | } |
145 | { | ||
146 | p.bump_remap(T![default]); | ||
147 | has_mods = true; | ||
148 | } | 133 | } |
134 | |||
149 | if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { | 135 | if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { |
150 | p.bump_remap(T![existential]); | 136 | p.bump_remap(T![existential]); |
151 | has_mods = true; | 137 | has_mods = true; |