aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcsmoe <[email protected]>2018-09-25 15:00:43 +0100
committercsmoe <[email protected]>2018-09-25 15:21:16 +0100
commitedf1cc3582a842837d64fa6ec08df00c028521f9 (patch)
tree822401b43f30102651165ce1057d31ac06604a00
parentcacb32d88aa27b8e671173571325756890941b06 (diff)
parse impl type
-rw-r--r--crates/ra_syntax/src/grammar/items/traits.rs26
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs3
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt72
3 files changed, 44 insertions, 57 deletions
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs
index 25b6cb66b..62ab877fc 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/grammar/items/traits.rs
@@ -54,16 +54,8 @@ pub(super) fn impl_item(p: &mut Parser) {
54 54
55 // test impl_item_neg 55 // test impl_item_neg
56 // impl !Send for X {} 56 // impl !Send for X {}
57 if p.at(IMPL_KW) { 57 p.eat(EXCL);
58 p.error("expected type"); 58 impl_type(p);
59 } else {
60 p.eat(EXCL);
61 if p.at(IMPL_KW) {
62 p.error("expected type");
63 } else {
64 types::type_(p);
65 }
66 }
67 if p.eat(FOR_KW) { 59 if p.eat(FOR_KW) {
68 types::type_(p); 60 types::type_(p);
69 } 61 }
@@ -123,3 +115,17 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
123 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 115 (p.nth(1) == LIFETIME || p.nth(1) == IDENT)
124 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) 116 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ)
125} 117}
118
119// impl Type {}
120// ^^^^
121// impl Trait for T {}
122// ^^^^^
123pub(crate) fn impl_type(p: &mut Parser) {
124 if p.at(IMPL_KW) {
125 p.error("expected trait or type");
126 return;
127 }
128 types::type_(p);
129}
130
131
diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs
index c4f5eca87..eac922109 100644
--- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs
+++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.rs
@@ -1,4 +1,3 @@
1impl<T: Clone> 1impl<T: Clone>
2impl<T:Clone> 2impl<T> OnceCell<T> {
3!impl<T> OnceCell<T> {
4} 3}
diff --git a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt
index 60b65bce5..60337d6de 100644
--- a/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt
+++ b/crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt
@@ -1,4 +1,4 @@
1ROOT@[0; 54) 1ROOT@[0; 39)
2 IMPL_ITEM@[0; 14) 2 IMPL_ITEM@[0; 14)
3 IMPL_KW@[0; 4) 3 IMPL_KW@[0; 4)
4 TYPE_PARAM_LIST@[4; 14) 4 TYPE_PARAM_LIST@[4; 14)
@@ -14,53 +14,35 @@ ROOT@[0; 54)
14 NAME_REF@[8; 13) 14 NAME_REF@[8; 13)
15 IDENT@[8; 13) "Clone" 15 IDENT@[8; 13) "Clone"
16 R_ANGLE@[13; 14) 16 R_ANGLE@[13; 14)
17 err: `expected type` 17 err: `expected trait or type`
18 err: `expected `{`` 18 err: `expected `{``
19 WHITESPACE@[14; 15) 19 WHITESPACE@[14; 15)
20 IMPL_ITEM@[15; 30) 20 IMPL_ITEM@[15; 38)
21 IMPL_KW@[15; 19) 21 IMPL_KW@[15; 19)
22 TYPE_PARAM_LIST@[19; 28) 22 TYPE_PARAM_LIST@[19; 22)
23 L_ANGLE@[19; 20) 23 L_ANGLE@[19; 20)
24 TYPE_PARAM@[20; 27) 24 TYPE_PARAM@[20; 21)
25 NAME@[20; 21) 25 NAME@[20; 21)
26 IDENT@[20; 21) "T" 26 IDENT@[20; 21) "T"
27 COLON@[21; 22) 27 R_ANGLE@[21; 22)
28 PATH_TYPE@[22; 27) 28 WHITESPACE@[22; 23)
29 PATH@[22; 27) 29 PATH_TYPE@[23; 34)
30 PATH_SEGMENT@[22; 27) 30 PATH@[23; 34)
31 NAME_REF@[22; 27) 31 PATH_SEGMENT@[23; 34)
32 IDENT@[22; 27) "Clone" 32 NAME_REF@[23; 31)
33 R_ANGLE@[27; 28) 33 IDENT@[23; 31) "OnceCell"
34 WHITESPACE@[28; 29) 34 TYPE_ARG_LIST@[31; 34)
35 EXCL@[29; 30) 35 L_ANGLE@[31; 32)
36 err: `expected type` 36 TYPE_ARG@[32; 33)
37 err: `expected `{`` 37 PATH_TYPE@[32; 33)
38 IMPL_ITEM@[30; 53) 38 PATH@[32; 33)
39 IMPL_KW@[30; 34) 39 PATH_SEGMENT@[32; 33)
40 TYPE_PARAM_LIST@[34; 37) 40 NAME_REF@[32; 33)
41 L_ANGLE@[34; 35) 41 IDENT@[32; 33) "T"
42 TYPE_PARAM@[35; 36) 42 R_ANGLE@[33; 34)
43 NAME@[35; 36) 43 WHITESPACE@[34; 35)
44 IDENT@[35; 36) "T" 44 ITEM_LIST@[35; 38)
45 R_ANGLE@[36; 37) 45 L_CURLY@[35; 36)
46 WHITESPACE@[37; 38) 46 WHITESPACE@[36; 37)
47 PATH_TYPE@[38; 49) 47 R_CURLY@[37; 38)
48 PATH@[38; 49) 48 WHITESPACE@[38; 39)
49 PATH_SEGMENT@[38; 49)
50 NAME_REF@[38; 46)
51 IDENT@[38; 46) "OnceCell"
52 TYPE_ARG_LIST@[46; 49)
53 L_ANGLE@[46; 47)
54 TYPE_ARG@[47; 48)
55 PATH_TYPE@[47; 48)
56 PATH@[47; 48)
57 PATH_SEGMENT@[47; 48)
58 NAME_REF@[47; 48)
59 IDENT@[47; 48) "T"
60 R_ANGLE@[48; 49)
61 WHITESPACE@[49; 50)
62 ITEM_LIST@[50; 53)
63 L_CURLY@[50; 51)
64 WHITESPACE@[51; 52)
65 R_CURLY@[52; 53)
66 WHITESPACE@[53; 54)