From d04473accb1a22abdb2262d0e8954beaf28ae364 Mon Sep 17 00:00:00 2001 From: csmoe Date: Wed, 19 Jun 2019 14:25:10 +0800 Subject: fix: specialization(with blindly parsing) Change-Id: Ic5d2767e8781568d76d4d0013cd6081e95ae8a95 --- crates/ra_parser/src/grammar/items.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser/src/grammar/items.rs') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index e85147e9e..424d0476d 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -103,7 +103,21 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul p.bump_remap(T![auto]); has_mods = true; } - if p.at(IDENT) && p.at_contextual_kw("default") && p.nth(1) == T![impl] { + + if p.at(IDENT) + && p.at_contextual_kw("default") + && (match p.nth(1) { + T![impl] => true, + T![fn] | T![type] => { + if let ItemFlavor::Mod = flavor { + true + } else { + false + } + } + _ => false, + }) + { p.bump_remap(T![default]); has_mods = true; } @@ -163,12 +177,25 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // test default_impl // default impl Foo {} + // test_err default_fn_type + // trait T { + // default type T = Bar; + // default fn foo() {} + // } + + // test default_fn_type + // impl T for Foo { + // default type T = Bar; + // default fn foo() {} + // } + // test unsafe_default_impl // unsafe default impl Foo {} T![impl] => { traits::impl_block(p); m.complete(p, IMPL_BLOCK); } + // test existential_type // existential type Foo: Fn() -> usize; T![type] => { -- cgit v1.2.3